VSCode配置C/C++語言環(huán)境(2023最新版)
基本步驟:
下載并安裝VSCode
vscode下載地址 https://code.visualstudio.com/
不會(huì)安裝vscode的看下方博客:
安裝C++插件
安裝編譯器(MinGW-W64 GCC)
C編譯器(MinGW-W64 GCC)下載地址:
https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
在線下載的exe文件一般是會(huì)有網(wǎng)絡(luò)的問題,導(dǎo)致下載不了,建議windows64位直接下載8.1.0版本的x86_64-win32-seh或者x86_64-posix-seh。兩者在多線程方面有些許差異,一般情況不會(huì)用到該功能,所以兩者皆可。下載后用解壓軟件解壓即可。
配置環(huán)境變量
找到這個(gè)文件夾內(nèi)的一個(gè)叫bin的文件夾,然后把它的地址復(fù)制一下:
打開之后將剛剛復(fù)制的地址添加進(jìn)去:
然后點(diǎn)確定,之前彈出的所有頁面都點(diǎn)擊確定。然后測試環(huán)境配置是否成功:
Win+R快捷鍵打開運(yùn)行窗口,在里面輸入cmd,回車打開cmd.exe
在cmd.exe中輸入如下命令:
gcc -v -E -x c++ -
如果運(yùn)行結(jié)果像下方圖片中這樣,就配置成功了。
配置
最后在VSCode中進(jìn)行相關(guān)配置:
先新建一個(gè)文件夾作為C語言項(xiàng)目文件,然后點(diǎn)擊菜單欄中的File——>Open Folder,找到剛才新建的文件夾,然后點(diǎn)擊選擇文件夾打開這個(gè)項(xiàng)目文件。
然后在里面新建一個(gè)hello.c文件(名字隨便起,以.c結(jié)尾就行了)
然后再建一個(gè)
.vscode文件夾(注意前面有個(gè)點(diǎn)),在里面建三個(gè)文件,c_cpp_properties.json、launch.json、tasks.json
c_cpp_properties.json:將這段代碼復(fù)制進(jìn)去
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "C:/MinGW-W64 GCC/mingw64/include/**", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "msvc-x64", "browse": { "limitSymbolsToIncludedHeaders": true, "databaseFilename": "", "path": [ "${workspaceRoot}", "C:/MinGW-W64 GCC/mingw64/include/**", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "C:/MinGW-W64 GCC/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ] } } ], "version": 4 }
然后,下方紅框里的內(nèi)容需要修改,將所有的改為自己的安裝路徑:
launch.json:復(fù)制粘貼,然后miDebuggerPath屬性里的內(nèi)容也要改成自己的路徑
{ "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": [], "console":"externalTerminal" }, { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "C:\\MinGW-W64 GCC\\mingw64\\bin\\gdb.exe",// 自己電腦的gdb "preLaunchTask": "echo",//這里和task.json的label相對應(yīng) "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
tasks.json:復(fù)制粘貼
{ // 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",//解決中文亂碼 "-lstdc++"http://解決只能運(yùn)行c不能運(yùn)行c++ ] } ], "presentation": { "echo": true, "reveal": "always", "focus": false, "panel": "shared", "showReuseMessage": true, "clear": false } }
然后就可以在之前建的hello.c文件里面寫程序啦,比如我們熟悉的hello world:
#include<stdio.h> main() { printf("hello world\n"); //system("pause"); }
程序閃退問題
上面的三個(gè)文件只要復(fù)制正確,路徑改成自己的閃退問題就已經(jīng)解決
實(shí)在不行你就把輸入
system("pause");
f5運(yùn)行結(jié)果:
vscode配置c/c++環(huán)境就配置完成。
到此這篇關(guān)于VSCode配置C/C++語言環(huán)境(2023最新版)的文章就介紹到這了,更多相關(guān)VSCode配置C/C++內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
解決pip?install?dlib報(bào)錯(cuò)C++11?is?required?to?use?dlib
這篇文章主要介紹了在使用pip?install?dlib安裝dlib的時(shí)候報(bào)錯(cuò)C++11?is?required?to?use?dlib的解決方法,需要的的小伙伴可以參考一下,希望對你有所幫助2022-02-02C++實(shí)現(xiàn)時(shí)間轉(zhuǎn)換及格式化
這篇文章主要為大家詳細(xì)介紹了C++中實(shí)現(xiàn)時(shí)間轉(zhuǎn)換及格式化的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-11-11C++實(shí)現(xiàn)LeetCode(163.缺失區(qū)間)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(163.缺失區(qū)間),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C語言數(shù)據(jù)結(jié)構(gòu)之單鏈表存儲(chǔ)詳解
鏈表是一種物理存儲(chǔ)結(jié)構(gòu)上非連續(xù)、非順序的存儲(chǔ)結(jié)構(gòu),數(shù)據(jù)元素的邏輯順序是通過鏈表中的指針鏈接次序?qū)崿F(xiàn)的。本文將和大家一起聊聊C語言中單鏈表的存儲(chǔ),感興趣的可以學(xué)習(xí)一下2022-07-07