简体   繁体   中英

Visual Studio Code C++: unordered_map not found

I was given some C++ files that I need to compile. I'm using Visual Studio Code with the C/C++ and Code Runner extensions on Windows 10. With the following "include" statements:

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

I get the following error:

unordered_map: No such file or directory

I am very new to C++, and haven't been able to find a solution to this problem. I've updated the "includePath" in my c_cpp_properties.json file as follows. I have also tried compiling with Cygwin and Visual Studio Community, but I get the same error. I know the unordered_map .hpp file exists, but the compiler doesn't seem to be finding it.

"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

If it's relevant, this is what my tasks.json file looks like:

"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"
    }
]

Are my .json files configured properly? I apologize if I'm missing something basic; I've done a lot of searching on how to compile C++ on Windows, and haven't had any success. Thank you in advance for any help.

EDIT: Here is the full file I'm trying to compile. The executable is meant to be called by a python script.

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

You are using msbuild at the moment to build your project. Is this intentional? If you just have "some C++ files" you want to compile, msbuild is an overkill, compile the source directly by either using Mingw's g++ or the Microsoft CL.exe compiler.

So I recommend:

1) Go to http://mingw-w64.org/doku.php/download , download and install mingw and add the path to g++ into your PATH environment variable.

2) In Visual Studio Code create a task.json with the following content:

{
    "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 (assuming you store mingw here: 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
}

Unordered map is not supported in VS Code by default Microsoft ms-vscode.cpptools. Follow these steps to get over the problem:

  1. Download MinGW from ( https://sourceforge.net/projects/mingw/ ). MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import libraries and header files for building native Windows applications. Mark all the packages for installation. ss to mark all the packages for installation Click on the Apply Changes option under the Installation tab ss of where to click on apply changes

  2. Now, the Environment Variable's Path is to be updated. Go to Advanced System Settings->Environment Variables. Edit Path in System Variables Tab. ss of how to edit Path Copy the path of the bin folder of MinGW. By default, the path is: C:\\MinGW\\bin Paste this new path in the list and click OK. ss after pasting the bin path into the list

  3. Run the C++ code in VS Code. It will work fine. ss of vs code working fine at last

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM