环境 shell
OS::Microsoft Windows [Version 10.0.17134.285] x64json
VSC:Version:1.27.2 (system setup)windows
VS:2017visual-studio-code
心血来潮想使用VSC来写C++,官方文档和网上大多资料都是使用g++进行编译的。这里给出使用MSVC的方案。visual-studio
参考了《用Visual Studio Code 来生成您的C++应用程序》的方法,当给出的版本太旧,在最新的win10上会有错误。 ui
以后会生成.vscode文件夹和c_cpp_properties.json文件。spa
@echo off 插件 call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 命令行 set compilerflags=/Od /Zi /EHsc 调试 set linkerflags=/OUT:helloworld.exe cl.exe %compilerflags% helloworld.cpp /link %linkerflags% |
注意将vcvarsall.bat路径替换成你本身的,若是是32位系统,须要将x64替换位x86。
修改成以下参数:
顺利的话就能在EXPLORER窗口看到编译后的程序。
使用MSVC编译的话,调试配置会比较方便。
启动参数能够修改args参数。
更多调试的操做,能够参考《C/C++ for Visual Studio Code (Preview)》
多文件编译能够参考《Walkthrough: Compiling a Native C++ Program on the Command Line》,编写相应的build.bat便可。
参考资料:
用Visual Studio Code 来生成您的C++应用程序
From <https://blogs.msdn.microsoft.com/c/2016/12/20/%E7%94%A8visual-studio-code-%E6%9D%A5%E7%94%9F%E6%88%90%E6%82%A8%E7%9A%84c%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F/>
Walkthrough: Compiling a Native C++ Program on the Command Line
From <https://msdn.microsoft.com/en-us/library/ms235639.aspx?f=255&MSPPError=-2147217396>
C/C++ for Visual Studio Code (Preview)From <https://code.visualstudio.com/docs/languages/cpp>