C/C++ Compile Run 扩展使用教程
1. 项目的目录结构及介绍
C/C++ Compile Run 是一个用于 Visual Studio Code 的扩展,旨在简化 C/C++ 文件的编译和运行过程。项目的目录结构如下:
c-cpp-compile-run/
├── .vscode/
│ ├── extensions.json
│ ├── settings.json
│ └── tasks.json
├── src/
│ ├── main.cpp
│ └── utils.cpp
├── include/
│ └── utils.h
├── README.md
└── .gitignore
- .vscode/: 包含 Visual Studio Code 的配置文件。
- extensions.json: 推荐的扩展列表。
- settings.json: 项目的全局设置。
- tasks.json: 定义编译和运行任务。
- src/: 包含源代码文件。
- main.cpp: 主程序文件。
- utils.cpp: 工具函数实现文件。
- include/: 包含头文件。
- utils.h: 工具函数的声明文件。
- README.md: 项目说明文档。
- .gitignore: Git 忽略文件配置。
2. 项目的启动文件介绍
项目的启动文件是 src/main.cpp。这个文件包含了程序的入口点 main 函数。以下是 main.cpp 的示例代码:
#include <iostream>
#include "utils.h"
int main() {
std::cout << "Hello, World!" << std::endl;
printMessage();
return 0;
}
- #include : 引入标准输入输出流库。
- #include "utils.h": 引入自定义头文件。
- int main(): 程序的入口函数。
3. 项目的配置文件介绍
项目的配置文件主要位于 .vscode/ 目录下,以下是各个配置文件的介绍:
settings.json
{
"c-cpp-compile-run.c-compiler": "/usr/bin/gcc",
"c-cpp-compile-run.cpp-compiler": "/usr/bin/g++",
"c-cpp-compile-run.save-before-compile": true,
"c-cpp-compile-run.c-flags": "-Wall -Wextra -g3",
"c-cpp-compile-run.cpp-flags": "-Wall -Wextra -g3",
"c-cpp-compile-run.run-args": "",
"c-cpp-compile-run.run-in-external-terminal": false,
"c-cpp-compile-run.should-show-notifications": true,
"c-cpp-compile-run.output-location": "",
"c-cpp-compile-run.custom-run-prefix": ""
}
- c-cpp-compile-run.c-compiler: C 编译器路径。
- c-cpp-compile-run.cpp-compiler: C++ 编译器路径。
- c-cpp-compile-run.save-before-compile: 编译前是否保存文件。
- c-cpp-compile-run.c-flags: C 编译器标志。
- c-cpp-compile-run.cpp-flags: C++ 编译器标志。
- c-cpp-compile-run.run-args: 运行时的参数。
- c-cpp-compile-run.run-in-external-terminal: 是否在外部终端运行。
- c-cpp-compile-run.should-show-notifications: 是否显示通知。
- c-cpp-compile-run.output-location: 编译输出文件的自定义位置。
- c-cpp-compile-run.custom-run-prefix: 运行前的前缀命令。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile and Run",
"type": "shell",
"command": "g++",
"args": [
"-g",
"src/main.cpp",
"src/utils.cpp",
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



