0 Preface/Foreword
1、安装VScode
官网:Download Visual Studio Code - Mac, Linux, Windows
文档:Documentation for Visual Studio Code
1.1 优点
- Intelligent code completion: code smarter with intellisense - completions for variables, methods, and imported modules.
- Streamlined debugging: Print debugging is a thing of the past. Debug in VS Code with your terminal tools
- Fast, Powerful Editing: Linting, multi-cursor editing, parameters hints, and other powerful editing features
- Code Navigation and refactoring: Browse your source code quickly using peek and navigate to definition
- In-product source control: speed up your release cycle with SCM support inside your editor, including rich Git integration
1.2 添加扩展插件
1.2.1 添加C/C++extension
下载市场,marketplace:C/C++ - Visual Studio Marketplace
C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, macOS. When you create a *.cpp file, the extension adds features such as syntax highlighting (colorization), smart completions and hovers (IntelliSense), and error checking.
安装扩展步骤:
- 打开VS Code(Open VS Code)
- 选择在活动条中的扩展功能的可视图标(Select the Extension view icon on the Activity bar or use the keyboard shortcut(ctrl+shift+X))
- 搜索 C++(Search for 'C++')
- 选择安装(Select Install)
1.2.2 设置C++环境(set up C++ environment)
C++ is a compiled language meaning your program's souce code must be translated (compiled) before it can be run on your computer. The C/C++ extension doesn't include a C++ compiler or debugger, since VS Code as an editor relies on command-line tools for the development workflow. You need to install these tools or use those tools already installed on your computer.
检查你是否已经安装了编译器(Check if you have a compiler installed)
Note: There may already be a C++ compiler and debugger provided by your academic or work development environment. Check with your instructors or colleagues ofr guidance on installing the recommended C++ toolset (compiler, debugger, project system, linter).
Common compilers that already come preinstalled on some platforms are the GNU Compiler Collection (GCC) on Linux and the Clang tools with Xcode on macOS.
打开终端命令行窗口:
shift+ctrl+`
使用命令:
g++ version
The output should show you the compiler version and details. If neither are found, make sure your compiler executable is in your platform path (%PATH on Windows, $PATH on Linux and macOS) so that the C/C++ extension can find it. Otherwise, use the instructions in the section below to install a compiler.
安装MSYS2
注意:安装过程结束后,一定要选择运行UCRT64,否则无法加载mingw-w64-ucrt相关工具。
通过MSYS2安装MinGW64
配置环境变量:
验证mingw-64工具安装完成并且可用