Intellisense抱怨“命名空间std没有成员size_t”。如何消除此(错误)错误?

时间:2020-05-02 15:43:36

标签: visual-studio intellisense msys2

使用Visual Studio 2019“打开文件夹”项目。 Msys2,mingw64。

构建完成没有任何问题,但是IntelliSense抱怨:

命名空间“ std”没有成员“ size_t”

IntelliSense还列出了约5700个其他(错误)错误,但我想它们都是相关的。

如何正确配置IntelliSense,以使其不会像我提到的那样显示错误错误?

// CppProperties.json
{
  "configurations": [
    {
      "name": "Mingw64",
      "includePath": [
        "${workspaceRoot}\\src\\**",
        "C:\\tools\\msys64\\mingw64\\include",
        "C:\\tools\\msys64\\mingw64\\include\\c++\\9.1.0",
        "C:\\tools\\msys64\\mingw64\\include\\c++\\9.1.0\\x86_64-w64-mingw32",
        "C:\\tools\\msys64\\mingw64\\include\\c++\\9.1.0\\backward",
        "C:\\tools\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.1.0\\include",
        "C:\\tools\\msys64\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\9.1.0\\include-fixed",
        "C:\\tools\\msys64\\mingw64\\x86_64-w64-mingw32\\include"
      ],
      "intelliSenseMode": "windows-clang-x86",
      "environments": [
        {
          "PATH": "C:\\tools\\msys64\\usr\\bin",
          "MSYSTEM": "MINGW64",
          "CHERE_INVOKING": "1"
        }
      ]
    }
  ]
}

// .vs/tasks.vs.json
{
  "version": "0.2.1",
  "tasks": [
    {
      "taskLabel": "build",
      "appliesTo": "*",
      "contextType": "build",
      "type": "default",
      "command": "bash.exe",
      "args": [
        "--login",
        "-c",
        "\"sh build.sh\""
      ],
      "inheritEnvironments": [
        "Mingw64"
      ]
    }
  ]
}

1 个答案:

答案 0 :(得分:1)

Intellisense抱怨“命名空间std没有成员size_t”。怎么样 我可以删除此(假)错误吗?

由VS Code和VS创建的项目是不一致的,它们具有不同的结构,因此,如果从VSCode迁移到VS,将会有很多问题。

通常,在VS中,C ++项目中有一个xxx.vcxproj项目文件来控制文件的结构,然后MSBuild读取xxx.vcxproj文件来构建您的项目。并且,当您打开项目时,应使用xxx.slnxxx.vcxproj文件。

在VS Code中,通常在一个文件夹中是一个cpp文件,它与task.json和其他文件结合在一起以进行构建或调试。如果将其导入VS,则它只是一个文件夹,其中包含与VS IDE中的项目结构不一致的cpp文件和json文件。

毕竟,在VS中,the header file is stored in the project properties,而vs代码将文件地址存储在xxx.json文件中。您可以在VS中创建一个c ++控制台项目进行比较,右键单击该项目-> Properties-> VC++ Directories-> Include Directories

enter image description here

以上内容只是为了解释VS和VS IDE之间的区别。

建议

1),首先,请确保已导入:

#include <iostream>

2)关闭VS实例,删除.vs隐藏的文件夹,输出文件,然后重新打开您的项目,重新构建几次以对其进行测试。

3)尝试在VS中创建一个新的c ++项目,然后将您的vscode c ++项目迁移到其中(将cpp文件复制到其中并以我的方式配置相关的库)。并且请在VS IDE中保持一致的结构。