赞
踩
您可以通过在“扩展”视图(Ctrl + Shift + X)中搜索“ c++”来安装C/C++扩展。
在开始第二步之前,确保你已经安装了visual studio 2019的Microsoft Visual C ++(MSVC)编译器工具集。我之前安装了visual studio 2019的企业版,所以就不用安装了。
变量名 | 值 |
---|---|
PATH | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\bin\Hostx64\x64 |
INCLUDE | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\include |
INCLUDE | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\SDK\ScopeCppSDK\vc15\SDK\include\shared |
INCLUDE | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\SDK\ScopeCppSDK\vc15\SDK\include\ucrt |
INCLUDE | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\SDK\ScopeCppSDK\vc15\SDK\include\um |
LIB | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\lib\x64 |
LIB | C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\SDK\ScopeCppSDK\vc15\SDK\lib |
每次修改环境变量应用确定更新之后,一定要重新打开vscode读取环境变量更新后的值。
主要涉及tasks.json、launch.json和settings.json这三个文件,详细操作参考https://code.visualstudio.com/docs/cpp/config-msvc
其实配置文件都是按照官网指引操作之后生成的默认json文件,下面是我生成json文件的内容
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "(Windows) 启动", "type": "cppvsdbg", "request": "launch", "program": "${workspaceFolder}/Test.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false } ] }
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "C/C++: cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/Fe:", "${fileDirname}\\${fileBasenameNoExtension}.exe", "${workspaceFolder}\\Test.cpp" ], "problemMatcher": [ "$msCompile" ], "group": { "kind": "build", "isDefault": true } } ] }
如果你要生成多个文件,可以将
"${workspaceFolder}\\Test.cpp"
改为
"${workspaceFolder}\\*.cpp"
这样就不用局限于只编译一个文件了。
{
"files.associations": {
"vector": "cpp",
"string": "cpp",
"iostream": "cpp"
}
}
#include <iostream> #include <vector> #include <string> #include <unordered_map> using namespace std; int main(){ unordered_map<int, int> m; vector<int> vlist; vlist.push_back(1); vlist.push_back(2); vector<int>::iterator beg = vlist.begin(); vector<int>::iterator end = vlist.end(); for(;beg!=end;beg++) { cout<<*beg<<endl; } system("pause"); return 0; }
编译完成之后,会比原来多出一些文件,估计是一些链接文件以及中间代码。
用vscode装上leetcode插件刷算法题,启动速度和提交代码都方便不少,但是很多东西需要自己设置,有时候还会报出一些莫名其妙的错误,调也能调很久,耗时费力,整体感受还不如visual studio 2019方便。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。