VSCode C++环境配置,exe文件重定向

VSCode C++环境配置,exe文件重定向,第1张

文章目录
  • VSCode配置
  • 重拾C++基本语法:

VSCode配置

1.mingw 下载和环境变量设置
2.code runner配置
1)创建一个.vscode的文件夹,下面放三个文件launch.json,settings.json,tasks.json
配置参考

launch.json
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {//包含Debug配置
            "name": "gcc.exe - 生成和调试活动文件",//配置名称
            "type": "cppdbg", //配置类型,对应cpptools提供的调试功能
            "request": "launch", //请求配置类型,可以是启动/附加类型[launch/attach]
            "program": "${fileDirname}\build\${fileBasenameNoExtension}.exe",//待调试程序本地路径
            "args": [], //程序调试时传递给程序的命令行参数,设为空值
            "stopAtEntry": false,//改为true时程序暂停在程序入口位置,即main处打上断点
            "cwd": "${workspaceFolder}", //调试程序时的工作目录,这里表示源码目录
            "environment": [], //环境变量,设为空值
            "externalConsole": true, //true:cmd窗口; false:Vscode的内置终端输出
            "MIMode": "gdb", //指定连接的调试器,minGW64中调试程序->gdb
            "miDebuggerPath": "D:\ProgLang_Compilers\minGw\mingw64\bin\gdb.exe", //指定调试器所在路径,安装位置不同注意需要修改,间隔为\
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: gcc.exe 生成活动文件" //调试开始前执行需要执行的任务,调试前要编译构建 名称要和tasks.json的label保持一致
        }
    ]
}
tasks.json
{
    "tasks": [
        {//构建配置项
            "type":"shell",//任务类型,Vscode将预定义变量转义解析后直接传给command;shell->先打开shell再输入命令,因此args会经过shell再次解析
            "label": "C/C++: gcc.exe 生成活动文件",//任务名称
            "command": "D:\ProgLang_Compilers\minGw\mingw64\bin\gcc.exe",//本地编译器路径
            "args": [ //包含传给gcc命令的参数,用于实现特定功能
                "-g", //生成和调试有关的信息
                "${file}", //指定编译文件为当前文件
                "-o",//指定输出文件的路径和名称
                "${fileDirname}\build\${fileBasenameNoExtension}.exe"//修改.exe文件生成位置
            ],
            "options": {
                "cwd":"${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {//包含很多task,归为group
                "kind": "build",//表名该组任务类型是构建
                "isDefault": true//表明此任务为此组任务中的默认任务
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}
settings.json
{
    "files.associations": {
        "iostream": "cpp",
        "ostream":"cpp"
    },
    "code-runner.executorMap": {
        "cpp": " cd $dir && chcp 65001 && g++ $fileName -o ./build/$fileNameWithoutExt && ./build/$fileNameWithoutExt"
    }
}
重拾C++基本语法:
  1. 头文件(避免重复包含编译出错)
#pragma once
#ifndef _BINTREE_H_
#define _BINTREE_H_

#endif
  1. 模板类

template<class ElemType> class binTree{
    private:
 
    public:
    //构造函数
    binTree(){root=nullptr;}
    //拷贝构造函数
    binTree(const binTree<ElemType> &ctree){root=copyNode(ctree->root);}
    //析构函数
    ~binTree(){destroyNode(root);root=nullptr;}
    //赋值运算符重载函数
    binTree<ElemType>& operator=(const binTree<ElemType> &ctree);

};

template<class ElemType> binTree<ElemType>::binTree(){
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/915179.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存