小白上手vscode

本文主要针对使用 c + + c++ O I e r OIer (因为其他东西我都没学),有很多东西走了弯路,希望能以微薄的力量帮助大家学习.

本人主要学习来源:
https://www.luogu.org/blog/GNAQ/VSC-guide
https://www.luogu.com.cn/blog/crab-in-northeast/great-features-and-plugins-for-vscode
请先阅读以上内容.

下面介绍流程:

  1. 官网下载
  2. 下载MinGW(一般有Dev-c++的应该有吧,直接找到位置即可).
  3. bin添加到path系统变量内.
  4. 在左侧栏找到 拓展 按钮,这就是vscode的应用商店,可以下载到很多好用的插件和主题颜色.
    基本插件:“Chinese”(汉化界面),“C/C++”,“C/C++ compile runner”.
  5. 简单界面介绍:
    左侧栏依次为:资源管理器,搜索,源代码管理,运行,拓展.
    左下角可以访问设置.
    快捷键:
    Ctrl +shift + p,查找,以下简称find.
    F5,debug
    Ctrl+Alt+n,运行compile run.

打开文件夹后,会自动生成一个.vscode的文件夹,内置launch.json,tasks.json...
(tasks.json主要负责编译,launch.json主要负责调试,里面有很多配置环境设置)

直接复制我的 t a s k s . j s o n : tasks.json: (命令行参数可以自行调整)

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile",//标签(类似函数名),vscode的注释是不影响使用的哦
            "command": "g++",
            "args": ["-g","${file}", "-o", "${fileBasenameNoExtension}.exe","-Wall","-static-libgcc","-Wl,--stack=1000000000","-std=c++11"],//命令行参数
        },
        {
            "label": "CompileO2",
            "command": "g++",
            "args": ["-g","${file}", "-o", "${fileBasenameNoExtension}.exe", "-O2","-Wall","-static-libgcc","-Wl,--stack=1000000000","-std=c++11"],
        }
    ]
}

l a u n c h . j s o n : launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "G++ (with O2)",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "CompileO2"
        },
        {
            "name": "G++",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "Compile"
        }
    ]
}

注意:miDebuggerPath要设为系统的gdb.exe的绝对路径,斜杠要两条(’//’)

如果你是js神仙,你直接find:settings(json)即可进行修改设置.
但是如果是小白,那么可以去设置界面查找合适自己的选项.
比如:如果你想修改compile run的对c++的编译指令,那么可以在设置搜索executorMap,对cpp的命令.
我的设置为"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -std=c++14 -static-libgcc -Wall -Wextra && $dir$fileNameWithoutExt",
(中间位置其实可以自由选择)

调试代码时和Dev-c++类似,设置断点,然后在 监测 内输入表达是即可查找.

最后再分享几个比较有用的插件:

C++ Intellisense
Settings Sync
TabOut

现在你就成功入坑了vscode,你可以在 插件,快捷键,js 方面涉猎更多知识,以更方便的使用vscode.

猜你喜欢

转载自blog.csdn.net/qq_42886072/article/details/107927287