在vscode中可以使用code runner插件直接运行c++程序,而不需要在单独配置.vscode目录。
但是默认情况下只能运行c++单文件,如果目录下包含多个文件(.h .cpp .cpp),含有include包含关系,然后去运行main.cpp,会报错。
报错举例:
目录结构:  直接使用code runner插件运行main.cpp,报错如下: 
d:/mingw/bin/…/lib/gcc/mingw32/8.2.0/…/…/…/…/mingw32/bin/ld.exe: C:\Users\86155\AppData\Local\Temp\ccmttGXS.o:main.cpp:(.text+0x7f): undefined reference to `sort_array(int*, int)’ collect2.exe: error: ld returned 1 exit status
解决方法:
在设置中搜索 Code-runner: Executor Map  打开settings.json编辑:  输出 code-runner.executorMap ,回车  出现以下内容,将行内的 g++ $fileName 改为 g++ *.cpp 即可  再次尝试运行上述main.cpp,运行成功:  参考:
|