Reference: Macbook Pro install vscode and configure c/c++ environment
I am more concise here and have tested successfully.
Step 1:
Create an empty folder and open the folder with vscode.
Step 2:
Use vscode to create a new c++ file, fill in the content, save it, and name it main.cpp (arbitrary).
#include <iostream>
int main()
{
for(int i=0;i<5;i++){
std::cout<<"hey you"<<std::endl;
}
return 0;
}
Step 3:
Enter the shortcut key command+shift+p under the main.cpp project, select Tasks: Configure Task, and continue to select C/C++: clang++ to generate the active file.
Step 4:
At this point, a series of files are generated on the left. First modify the task.json file. Only modify the last line of "args""${fileDirname}/${fileBasenameNoExtension}.out"
Step 5:
Open the launch.json file on the left and modify the "cwd" behavior "${workspaceFolder}"
. Finally, modify the behavior of "program""${fileDirname}/${fileBasenameNoExtension}.out"
Step 6:
Return to the main.cpp interface, press the shortcut key command+shift+b, and select C/C++:clang++ to generate the active file. An .out file is generated at this point.
Step 7:
Put a breakpoint on main.cpp, and select run–>start debugging. At this point, the long-awaited debug function will appear.
In summary, only when the .out file is successfully generated can the debug be successful.