vscode下无法使用std::format

不当之处,敬请指正

如果你使用的是MINGW请往下看,如果是MSCV的话vs2019开始就支持了。(clang不是很清楚,应该是clang14)

gcc13.1.0的版本才支持。请注意是否版本下载错误。

步骤:

1.vscode官网下载vscode(system版方便设置存储位置,权限齐全)

2.MINGW下载gcc13.1.0或者更新的版本

3.安装vscode的c\c++和c\c++扩展等

4.选择一个文件夹空间,写一个简单的cpp文件并运行,自动生成.vscode文件(在该文件夹空间)

5.在.vscode文件空间中配置四个json文件,可以自动生成,但是也可以自己新建文件(当然自动生成的需要修改一些参数,不然不是c++20标准[doge],所以建议直接复制粘贴我写好的)

 

1. https://code.visualstudio.com/Download

2.https://www.mingw-w64.org/downloads/

下拉找到这个

打开GitHub在里面下载(怎么上GitHub下载自己搜一下)

把下载后的文件(mingw64)打开,可以看到bin文件夹,把这个地址复制下来(下载时最好搞全英文路径)

双击红色部分,复制地址

放到系统高级设置->环境变量->path->新建,粘贴上去。

然后逐步确认,返回

 

 

3.拓展如图(其实如果你下了一个运行cpp时vscode会提醒建议你补齐的)

4.直接新建文件,之后一直在这个文件夹下写(workplace),不然要重新搞.vscode

一个cpp样例:

#include <iostream>
using namespace std;
 
int main() 
{
    cout << "Hello, World!";
    return 0;
}

5..vscode下的四个json文件

 按照这个顺序给出代码

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "D:\\mingw64\\include",
                "D:\\mingw64\\x86_64-w64-mingw32\\include",
                "D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\13.1.0\\include",
                "D:\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\13.1.0\\include\\c++",
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "D:\\mingw64\\bin\\gcc.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}
{
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "enter program name, for example ${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/path/to/gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ],
    "version": "2.0.0"
}
{
    "files.associations": {
        "any": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "barrier": "cpp",
        "bit": "cpp",
        "*.tcc": "cpp",
        "bitset": "cpp",
        "cctype": "cpp",
        "cfenv": "cpp",
        "charconv": "cpp",
        "chrono": "cpp",
        "cinttypes": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "codecvt": "cpp",
        "compare": "cpp",
        "complex": "cpp",
        "concepts": "cpp",
        "condition_variable": "cpp",
        "coroutine": "cpp",
        "csetjmp": "cpp",
        "csignal": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdint": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cuchar": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "deque": "cpp",
        "forward_list": "cpp",
        "list": "cpp",
        "map": "cpp",
        "set": "cpp",
        "string": "cpp",
        "unordered_map": "cpp",
        "unordered_set": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "expected": "cpp",
        "algorithm": "cpp",
        "functional": "cpp",
        "iterator": "cpp",
        "memory": "cpp",
        "memory_resource": "cpp",
        "numeric": "cpp",
        "optional": "cpp",
        "random": "cpp",
        "ratio": "cpp",
        "regex": "cpp",
        "source_location": "cpp",
        "string_view": "cpp",
        "system_error": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "format": "cpp",
        "fstream": "cpp",
        "future": "cpp",
        "initializer_list": "cpp",
        "iomanip": "cpp",
        "iosfwd": "cpp",
        "iostream": "cpp",
        "istream": "cpp",
        "latch": "cpp",
        "limits": "cpp",
        "mutex": "cpp",
        "new": "cpp",
        "numbers": "cpp",
        "ostream": "cpp",
        "ranges": "cpp",
        "scoped_allocator": "cpp",
        "semaphore": "cpp",
        "shared_mutex": "cpp",
        "span": "cpp",
        "spanstream": "cpp",
        "sstream": "cpp",
        "stacktrace": "cpp",
        "stdexcept": "cpp",
        "stdfloat": "cpp",
        "stop_token": "cpp",
        "streambuf": "cpp",
        "syncstream": "cpp",
        "thread": "cpp",
        "typeindex": "cpp",
        "typeinfo": "cpp",
        "valarray": "cpp",
        "variant": "cpp"
    }
}
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "D:\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "-std=c++2a",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

完成!

 

posted @ 2023-09-27 11:58  silverAugustine  阅读(639)  评论(0)    收藏  举报