VSCode快速配置C语言环境-创新互联

 1.在VSCode中安装C/C++插件watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAI0NCMTUw,size_20,color_FFFFFF,t_70,g_se,x_162.下载mingw64

MinGW-w64官方网站首页

创新互联服务项目包括南通网站建设、南通网站制作、南通网页制作以及南通网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,南通网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到南通省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!1、找到downloads

2、找到SourceForge

3、找到一个合适的版本(我这里是下拉找到免安装版)下载,其他的都试过了,都不行(可能是因为外网的关系连接不稳定)

4、直接解压到想要的位置

5.将mingw64添加到环境变量 

将下载好的mingw64解压到指定的目录,我的路径是C:\Program Files\mingw64,然后配置环境变量 将目录C:\Program Files\mingw64\bin加入到环境变量path里(注意修改为自己的mingw64路径,具体到bin文件夹)

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAI0NCMTUw,size_20,color_FFFFFF,t_70,g_se,x_16

打开命令行输入gcc -v,出现以下信息说明mingw64配置成功

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAI0NCMTUw,size_20,color_FFFFFF,t_70,g_se,x_16

4.新建.vscode文件夹 在该文件夹创建三个文件

f951e8a35a1c48a1a7273a8fb71eb033.png

点这里可以直接下载 再修改路径

.vscode文件下载

注意:c_cpp_properties.json和launch.json 需要修改路径

(1)c_cpp_properties.json配置

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceRoot}",
                "C:\\Program Files\\mingw64"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "__GNUC__=6",
                "__cdecl=__attribute__((__cdecl__))"
            ],
            "intelliSenseMode": "windows-gcc-x64",
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": "",
                "path": [
                    "${workspaceRoot}",
                    "C:\\Program Files\\mingw64"
                    //此处修改为自己mingw64的路径
                ]
            }
        }
    ],
    "version": 4
}

(2)launch.json配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "cmd",
            "preLaunchTask": "echo",
            "args": [
                "/C",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "&",
                "echo.",
                "&",
                "pause"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole":true
        },
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",//修改为自己电脑的gdb路径
            "preLaunchTask": "echo",//这里和task.json的label相对应
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
 
        }
    ]
}

(3)tasks.json配置

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g", 
                "${file}", 
                "-o", 
                "${fileBasenameNoExtension}.exe",
                "-fexec-charset=GBK"//解决中文乱码
            ]
        }
    ],
    "presentation": {
        "echo": true,
        "reveal": "always",
        "focus": false,
        "panel": "shared", 
        "showReuseMessage": true,
        "clear": false
    }
}
5.代码编译与运行
#includeint main()
{
   printf("Hello, World! \n");

   return 0;
}
ctrl+alt+n 运行

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAI0NCMTUw,size_20,color_FFFFFF,t_70,g_se,x_16

vscode配置c语言环境就完成了!

如果打印中文乱码,请看下面这篇文章

vscode 解决C语言printf打印中文乱码问题

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网页名称:VSCode快速配置C语言环境-创新互联
文章URL:http://myzitong.com/article/dcgosg.html