今天在使用 VS Code 的时候刷 PAT 的时候,有写到这样的一行语句:
for (char c : s1) {
编译时遇到了一条警告:![Warning: [-Wc++11-extensions]](https://code84.com/wp-content/uploads/2022/10/20210309163041722.png)
大意很明确,基于范围的 for 语句是 C++11 标准的内容,而我们这里使用的编译器是依据低于 C++11 的标准判断的。那么,如何在编译中指定所用标准呢?
在设置中找到 code-runner: executor map,选择在 settings.json 中编辑
找到 C++ 这一行
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
为它加上指定 C++ 标准的 flag 即可,如我要指定 C++11
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
参考:https://stackoverflow.com/questions/55111996/how-to-add-a-flag-when-running-code-runner-in-vscode
版权声明:本文为weixin_40553171原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。