1 prepare
1.1 check the clang
To check whether clang is shipped with the MAC, type the command line:
clang -v // or clang --version
Copy the code
MacOS can also run GCC to take care of user habits, but after MacOS10.12, the OS does not come with GCC. If not, to install it, type command line:
xcode-select --install
Copy the code
Follow the steps to complete the installation
1.2 Installation & OpeningVS Code
Do not install the Chinese language package
1.3 installing the C++ plug-in
Open VS Code by pressing the shortcut shift+command+X and search for C++. Click on it to make sure it’s Microsoft.
1.4 Creating a Demo file
In your usual project address, create a folder, and create a new C file (file suffix.c) and save it to the folder.
/* File hello.c */#include <stdio.h>
int main()
{
printf("hello world");
return 0;
}
Copy the code
2 configuration
Running C files in VS Code requires two JSON files to be configured
- launch.json
- tasks.json
2.1 launch. Json
Open the. C file, click on the top menu of the IDE, Run -> Start Debugging -> select C/C++: Clang Build active File
Json configuration document
2.2 the tasks. The json
Click open the. C file, command+ Shift +P to open the command line panel, and type Tasks :configure Task, Choose Tasks:Configure Task -> Select C/C++: GCC build active file Select C/C++:clang Build active file
3 Code Runner
The run. C file
Hover C file click the right mouse button -> Click Run Code, the terminal will output Hello World
[Running] cd "/Users/maggie/Sites/c-study/" && gcc hello.c -o hello && "/Users/maggie/Sites/c-study/"hello
Copy the code
Stop code run
Hover terminal OUTPUT -> Click the right mouse button to select Stop Code Run, if there is no such option students can open the command line panel input this command can also be.