Visual Studio代码C ++:找不到unordered_map

时间:2018-09-11 14:39:59

标签: c++ visual-studio-code include-path

为我提供了一些我需要编译的C ++文件。我正在Windows 10上将Visual Studio Code与C / C ++和Code Runner扩展一起使用,并带有以下“ include”语句:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <unordered_map>

我收到以下错误:

unordered_map: No such file or directory

我对C ++还是很陌生,还没有找到解决此问题的方法。我已经更新了c_cpp_properties.json文件中的“ includePath”,如下所示。我也曾尝试使用Cygwin和Visual Studio Community进行编译,但遇到相同的错误。我知道unordered_map .hpp文件存在,但是编译器似乎找不到它。

"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/include"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "windowsSdkVersion": "10.0.17134.0",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "msvc-x64"
    }
],
"version": 4

如果相关,这就是我的task.json文件的样子:

"version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "type": "shell",
        "command": "msbuild",
        "args": [
            // Ask msbuild to generate full paths for file names.
            "/property:GenerateFullPaths=true",
            "/t:build"
        ],
        "group": "build",
        "presentation": {
            // Reveal the output only if unrecognized errors occur.
            "reveal": "silent"
        },
        // Use the standard MS compiler pattern to detect errors, warnings and infos
        "problemMatcher": "$msCompile"
    }
]

我的.json文件是否配置正确?如果我缺少基本的东西,我深表歉意。我已经做了很多有关如何在Windows上编译C ++的搜索,但还没有取得任何成功。预先感谢您的帮助。

编辑: 这是我要编译的完整文件。该可执行文件本应由python脚本调用。

https://github.com/jorpjomp/sierra-hotel/blob/master/location_routing.cpp

2 个答案:

答案 0 :(得分:1)

默认情况下,VS Code 不支持无序映射 Microsoft ms-vscode.cpptools。请按照以下步骤解决问题:

  1. 从 ( https://sourceforge.net/projects/mingw/ ) 下载 MinGW。 MinGW 是 GNU Compiler Collection (GCC) 的原生 Windows 端口,具有可自由分发的导入库和用于构建原生 Windows 应用程序的头文件。

    标记所有要安装的软件包。 ss to mark all the packages for installation

    单击“安装”选项卡下的“应用更改”选项 ss of where to click on apply changes

  2. 现在,要更新环境变量的路径。转到高级系统设置-> 环境变量。

    在系统变量选项卡中编辑路径。 ss of how to edit Path

    复制MinGW的bin文件夹路径。默认路径为:C:\MinGW\bin

    将此新路径粘贴到列表中,然后单击“确定”。 ss after pasting the bin path into the list

  3. 在 VS Code 中运行 C++ 代码。它会正常工作。 ss of vs code working fine at last

答案 1 :(得分:0)

您目前正在使用msbuild来构建项目。这是故意的吗?如果您只想编译“某些C ++文件”,则msbuild是一个过大的杀伤力,请使用Mingw的g ++或Microsoft CL.exe编译器直接编译源代码。

所以我建议:

1)转到http://mingw-w64.org/doku.php/download,下载并安装mingw,然后将g ++的路径添加到PATH环境变量中。

2)在Visual Studio Code中,创建具有以下内容的task.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileBasenameNoExtension}"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

c_cpp_properties.json(假设您将mingw存储在此处:C:\ mingw \ mingw64 \ bin):

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/mingw/mingw64/bin",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}