VScode配置C++以及一些问题解决方案

如果有CLion的,那就用CLion吧,我个人觉得CLion是一个非常好的IDE.

Vscode配置C++

VScode配置C++的详细过程,请看官网:Get Started with C++ and Mingw-w64 in Visual Studio Code

但是配置文件略微稍有不同,我把所有配置的json文件贴在这里:

c_cpp_properties.json

{
   "configurations": [
     {
       "name": "GCC",
       "includePath": ["${workspaceFolder}/**"],
       "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
       "windowsSdkVersion": "10.0.18362.0",
       "compilerPath": "C:\\TCC\\Tools\\mingw64\\5.4.0_WIN64\\bin\\g++.exe",
       "cStandard": "c11",
       "intelliSenseMode": "gcc-x64"
     }
   ],
   "version": 4
 }

launch.json

{
   "version": "0.2.0",
   "configurations": [
     {
       "name": "g++.exe - Build and debug active file",
       "type": "cppdbg",
       "request": "launch",
       "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
       "args": [],
       "stopAtEntry": false,
       "cwd": "${workspaceFolder}",
       "environment": [],
       "externalConsole": true,
       "MIMode": "gdb",
       "miDebuggerPath": "C:\\TCC\\Tools\\mingw64\\5.4.0_WIN64\\bin\\gdb.exe",
       "setupCommands": [
         {
           "description": "Enable pretty-printing for gdb",
           "text": "-enable-pretty-printing",
           "ignoreFailures": true
         }
       ],
       "preLaunchTask": "C/C++: g++.exe build active file"
     }
   ]
 }

settings.json

{
   "files.associations": {
      "sstream": "cpp"
   }
}

tasks.json

{
   "version": "2.0.0",
   "tasks": [
     {
       "type": "shell",
       "label": "C/C++: g++.exe build active file",
       "command": "C:\\TCC\\Tools\\mingw64\\5.4.0_WIN64\\bin\\g++.exe",
       "args": ["-g","-std=c++17", "${fileDirname}\\**.cpp", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
       "options": {
         "cwd": "${workspaceFolder}"
       },
       "problemMatcher": ["$gcc"],
       "group": {
         "kind": "build",
         "isDefault": true
       }
     }
   ]
 }

Code Runner里settings.json

{
    "leetcode.endpoint": "leetcode-cn",
"editor.tabSize": 3,
"editor.detectIndentation": false,
"C_Cpp.updateChannel": "Insiders",
"cmake.configureOnOpen": true,
"code-runner.executorMapByFileExtension": {

   ".vb": "cd $dir && vbc /nologo $fileName && $dir$fileNameWithoutExt",
   ".vbs": "cscript //Nologo",
   ".scala": "scala",
   ".jl": "julia",
   ".cr": "crystal",
   ".ml": "ocaml",
   ".exs": "elixir",
   ".hx": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
   ".rkt": "racket",
   ".scm": "csi -script",
   ".ahk": "autohotkey",
   ".au3": "autoit3",
   ".kt": "cd $dir && kotlinc $fileName -include-runtime -d $fileNameWithoutExt.jar && java -jar $fileNameWithoutExt.jar",
   ".kts": "kotlinc -script",
   ".dart": "dart",
   ".pas": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
   ".pp": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
   ".d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
   ".hs": "runhaskell",
   ".nim": "nim compile --verbosity:0 --hints:off --run",
   ".csproj": "dotnet run --project",
   ".fsproj": "dotnet run --project",
   ".lisp": "sbcl --script",
   ".kit": "kitc --run",
   ".v": "v run",
   ".vsh": "v run",
   ".sass": "sass --style expanded",
   ".cu": "cd $dir && nvcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt" 
},
"code-runner.executorMapByGlob": {
   "pom.xml": "cd $dir && mvn clean package"
},
"code-runner.languageIdToFileExtensionMap": {

   "bat": ".bat",
   "powershell": ".ps1",
   "typescript": ".ts"
},
"code-runner.executorMap": {
   "javascript": "node",
   "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
   "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
   "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -std=c++11 && $dir$fileNameWithoutExt",
   "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
   "php": "php",
   "python": "python -u",
   "perl": "perl",
   "perl6": "perl6",
   "ruby": "ruby",
   "go": "go run",
   "lua": "lua",
   "groovy": "groovy",
   "powershell": "powershell -ExecutionPolicy ByPass -File",
   "bat": "cmd /c",
   "shellscript": "bash",
   "fsharp": "fsi",
   "csharp": "scriptcs",
   "vbscript": "cscript //Nologo",
   "typescript": "ts-node",
   "coffeescript": "coffee",
   "scala": "scala",
   "swift": "swift",
   "julia": "julia",
   "crystal": "crystal",
   "ocaml": "ocaml",
   "r": "Rscript",
   "applescript": "osascript",
   "clojure": "lein exec",
   "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
   "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
   "racket": "racket",
   "scheme": "csi -script",
   "ahk": "autohotkey",
   "autoit": "autoit3",
   "dart": "dart",
   "pascal": "cd $dir && fpc $fileName && $dir$fileName-------WithoutExt",
   "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
   "haskell": "runhaskell",
   "nim": "nim compile --verbosity:0 --hints:off --run",
   "lisp": "sbcl --script",
   "kit": "kitc --run",
   "v": "v run",
   "sass": "sass --style expanded",
   "scss": "scss --style expanded",
   "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
   "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
   "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
   "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
   "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"C_Cpp.intelliSenseEngine": "Tag Parser"
}

几个问题的参考链接:

1. 显示std no member of to_string

VsCode C++ namespace has no member错误_Mr_devil007的博客-CSDN博客

我在code runner 的settings.json文件已经加了这行代码了。

2. Unable to perform this action because the process is running.

Unable to perform this action because the process is running._My__Code的博客-CSDN博客

3. C++没有编译所有的文件,只编译了当前文件

linux - VS Code will not build c++ programs with multiple .ccp source files - Stack Overflow

后续有问题再更新,自己下次配置也方便点。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值