visual studio code C++开发基础配置

1、下载安装

Visual Studio Code - Code Editing. Redefined

安装完成后打开vscode,点击红色圈出区域,在搜索框分别搜索"C/C++"以及"chinese",安装C/C++插件(必须有)与简体中文插件

2、安装MinGW-w64

从清华大学镜像下载网速更快更稳定

msys2 | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source MirrorIndex of /msys2/distrib/x86_64/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

选最新版本

默认安装,在

bash 复制代码
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain

配置系统变量

3、调试代码:

cpp 复制代码
#include <iostream>
using namespace std;
 
class TaskQueue {
public:
    // 删除拷贝构造函数和赋值操作符
    TaskQueue(const TaskQueue& t) = delete;
    TaskQueue& operator=(const TaskQueue& t) = delete;
    
    // 公共的获取单例对象的函数
    static TaskQueue* getInstance() {
        if (m_taskQ == nullptr) {
            m_taskQ = new TaskQueue;
        }
        return m_taskQ;
    }
    
    // 成员函数
    void print() {
        cout << "我是单例对象的一个成员函数..." << endl;
    }
 
private:
    // 私有构造函数
    TaskQueue() = default;
 
    // 单例对象指针
    static TaskQueue* m_taskQ;
};
 
// 初始化静态成员变量
TaskQueue* TaskQueue::m_taskQ = nullptr;
 
int main() {
    // 获取单例对象并调用其成员函数
    TaskQueue::getInstance()->print();
    
    return 0;
}

修改默认的task.json配置文件

XML 复制代码
{
    "tasks": [
        {
            "type": "shell",                                      // 新任务采用shell运行
            "label": "C/C++: g++ 编译前清理",                      // 新任务名称为:C/C++: g++ 编译前清理
            "command": "rm",                                      // 执行rm命令,删除文件或目录
            "args": [
                "-rf",                                            // 递归删除,忽略文件不存在的情况
                "${fileDirname}/bin/${fileBasenameNoExtension}"   // 待删除文件路径
            ],
        },
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\msys64\\ucrt64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

参考资料:

VS Code 配置 C/C++ 编程运行环境(保姆级教程)_vscode配置c++环境-CSDN博客

相关推荐
blasit1 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_2 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星2 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛4 天前
delete又未完全delete
c++
端平入洛5 天前
auto有时不auto
c++
哇哈哈20216 天前
信号量和信号
linux·c++
多恩Stone6 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
蜡笔小马6 天前
21.Boost.Geometry disjoint、distance、envelope、equals、expand和for_each算法接口详解
c++·算法·boost
超级大福宝6 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
weiabc6 天前
printf(“%lf“, ys) 和 cout << ys 输出的浮点数格式存在细微差异
数据结构·c++·算法