Two problems that may be encountered when vscode configures c++ (header files cannot be found and compiled files cannot be found)

1. The header file cannot be found. There
is no need to change much . The header file can not be
found because you did not modify the includepath in c_cpp_properties.json to the location of the header files and libraries of the mingw or other compilers you installed.
Insert picture description here
2. Most compilation failures are gcc , Gdb, g++ did not add environment variables (or did not modify the place with text annotations in the tasks.json and launch.json files):
tasks.json
code:

"tasks": [        {
    
                
"type": "cppbuild",   
"label": "C/C++: g++.exe build active file",            "command": "C:\\msys64\\mingw32\\bin\\g++.exe",
/*这里是g++的位置,编译器的gcc、gdb、
g++都需要加入环境变量pash中,
大多问题都是这三个没有加入环境变量, */
    "args": [  
    "-g",               
    "${file}",   
    "-o",
    "${fileDirname}\\${fileBasenameNoExtension}.exe" 
                      
    ],
              
"options": {
    
      
 "cwd": "${workspaceFolder}" 
 },          
"problemMatcher": [                
"$gcc"          
  ],          
"group": {
    
        
"kind": "build"
"isDefault": true 
  },    
"detail": "Task generated by Debugger."    
    }    ], 
"version": "2.0.0"

Insert picture description here
launch.json
code:

{
    
        
"version": "0.2.0",
 "configurations": [{
    
     "name": "g++.exe - 生成和调试活动文件",   
 "type": "cppdbg",
 "request": "launch",
 "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
 "args": [],
 "stopAtEntry": false,  
 "cwd":"${workspaceFolder}", 
 "environment": [],             
 "externalConsole": true,//是否显示运行窗口 
 "MIMode": "gdb",
 "miDebuggerPath": "c:\\msys64\\mingw32\\bin\\gdb.exe",            /*这里是gdb的位置,编译器的
 gcc、gdb、g++都需要加入环境变量pash中,
 大多问题都是这三个没有加入环境变量,  */                      "setupCommands": [  {
    
                       
"description": "为 gdb 启用整齐打印",                    
"text": "-enable-pretty-printing",                    "ignoreFailures": true} 
  ],            
"preLaunchTask": "C/C++: g++.exe build active file"        }    ]}

Insert picture description here
I encountered these two problems. If you have other problems, please leave a message.
I am happy to help (in fact, I will only do this) but I am willing to solve other problems that may be encountered

Guess you like

Origin blog.csdn.net/zxb0215/article/details/113101541