How to write c++ code with vs code under linux system (small white article)


Preface

Used to get familiar with vs code under llinux for future use.


The following is the text of this article, reference: Station B: Goose bomb

1. How to install vscode?

Reference link: https://blog.csdn.net/ll596214569/article/details/106445990

Second, the compilation process

1. Create a workspace

The code is as follows (enter in the terminal):
Find the folder you want to put, open the terminal, and enter the following code.

mkdir EIGEN
code ./EIGEN

Get this workspace.

Insert picture description here
Install plugin: C++
Insert picture description here

2. C++ debugging

Create a .cpp file (note: the file type is related to the file name suffix).
Insert picture description here
Just write a C++ program

#include<iostream>
#include<string>
using namespace std;
int main(int argc,char **argv )
{
    
    
    cout<<"hello ltt"<<endl;
    return 0;
}

Create launch.json file

Insert picture description here
Environment selection: C++ (GDB/LLDB)

Insert picture description here
Then select g++ build and debug active file to get the .json file.
Insert picture description here
Create the task.json file (sequentially)
1. Go back to the .cpp file
2. ctrl+shift+p or F1 to open the command bar
3.tasks: Configure Task
4.C/ C++: g++ build active file
5. Get the result shown in the figure below

Insert picture description here
Join in the tasks.json file

"-std=c++17"

The location is as follows.
Insert picture description here
Then return to the cpp file and add a breakpoint. F5 runs.
Insert picture description here
Add an option in the launch.json file

 "internalConsoleOptions": "neverOpen",

In the blue position in the figure below:
Insert picture description here
return to find that the debugging is successful;


Guess you like

Origin blog.csdn.net/a840326/article/details/113176656