最近在用vscode作Cpp项目,在编译阶段发生如下问题:
[Running] cd "/Users/apple/Desktop/cs106L/simpleenroll_starter/" && g++ main.cpp -o main && "/Users/apple/Desktop/cs106L/simpleenroll_starter/"main
In file included from main.cpp:6:
./utils.cpp:146:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto it = std::find(v.begin(), v.end(), elem);
看error信息可以得知,肯定是Complier版本没跟上,C++11没有 auto 这个关键字。所以要改版本(其实手动编译的话直接-std=c++xx或者其他版本就可以解决,但是为了集成作者也得搞一下,其实vscode作为cpp的IDE真的有点麻烦,机制很复杂)
去defaultSetting.JSON这个页面找到executeMap函数,如下。
cpp就在executorMap里面,需要在这段话里main增加对cpp版本的定义
把executorMap全部复制出来,粘贴在目前文件所在目录的setting.json中,在g++后面增加-std=c++17即可运行成功。
tips:好逆天的ide,感觉比手动编译还麻烦