[Installation] mac configures the debug function of vscode and how to generate .out files.

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.
insert image description here

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"
insert image description here
insert image description here

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"
insert image description here

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. insert image description here
insert image description here
Step 7:
Put a breakpoint on main.cpp, and select run–>start debugging. At this point, the long-awaited debug function will appear.
insert image description here

In summary, only when the .out file is successfully generated can the debug be successful.

Guess you like

Origin blog.csdn.net/weixin_42326479/article/details/124392473