在vscode里面新建main. c没有自动生成. vscode的文件怎么办呀
时间: 2023-04-06 19:01:02 浏览: 291
您可以手动创建一个名为main.c的文件,然后在其中编写您的代码。在VSCode中,您可以通过单击“文件”菜单,然后选择“新建文件”来创建新文件。或者,您可以使用快捷键Ctrl+N(Windows)或Cmd+N(Mac)来创建新文件。
相关问题
vscode怎么新建c语言新项目
在Visual Studio Code (VSCode) 中新建C语言项目可以按照以下步骤进行:
1. **安装必要的扩展**:
- 打开VSCode,点击左侧的扩展图标(四个方块组成的图标)。
- 在搜索框中输入“C/C++”,找到由Microsoft发布的C/C++扩展并安装。
2. **创建项目文件夹**:
- 在你的计算机上创建一个新的文件夹,用于存放你的C语言项目。
- 打开VSCode,点击“文件” -> “打开文件夹”,选择你刚刚创建的文件夹。
3. **创建源代码文件**:
- 在VSCode的资源管理器中,点击“新建文件”图标。
- 输入文件名,例如`main.c`,然后按回车键。
4. **编写代码**:
- 在`main.c`文件中编写你的C语言代码。例如:
```c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
```
5. **配置任务**:
- 按`Ctrl+Shift+B`打开任务配置。
- 选择“C/C++: gcc build active file”选项,这将生成一个`tasks.json`文件。
- `tasks.json`文件内容大致如下:
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}
```
6. **编译和运行**:
- 按`Ctrl+Shift+B`进行编译。
- 编译成功后,打开终端(`Ctrl+`),输入以下命令运行程序:
```sh
./main
```
7. **调试配置**:
- 点击左侧的调试图标(一个虫子图标),然后点击“创建一个launch.json文件”。
- 选择“C/C++: (gdb) 启动”。
- `launch.json`文件内容大致如下:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为gdb启用整齐的打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
```
通过以上步骤,你就可以在VSCode中新建并运行一个C语言项目了。
vscode新建c语言项目
要在VS Code中新建一个C语言项目,您可以按照以下步骤进行操作:
1. 首先,在VS Code中安装C/C++官方插件。您可以在扩展视图中搜索"C/C++"并安装。
2. 安装完成后,打开VS Code,并点击左侧的资源管理器图标(文件夹图标),选择一个文件夹作为您的C语言项目的根目录。
3. 在资源管理器中,右键单击所选文件夹,并选择"新建文件",创建一个名为"main.c"的文件(或者您可以使用其他名称)。
4. 在"main.c"文件中,编写您的C语言代码。例如,您可以输入以下示例代码:
```c
#include <stdio.h>
int main(void) {
printf("Hello, World!");
return 0;
}
```
5. 保存并关闭"main.c"文件。
6. 在VS Code的顶部菜单中,选择"终端" -> "新建终端",以打开终端窗口。
7. 在终端窗口中,使用以下命令来编译和运行您的C语言程序:
```
gcc main.c -o main
./main
```
这将使用gcc编译您的"main.c"文件,并将可执行文件命名为"main"。然后,通过运行"./main"命令来执行生成的可执行文件。
以上步骤是在VS Code中新建C语言项目的基本流程。您可以根据自己的需要进行进一步的配置和调试。
阅读全文
相关推荐















