栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

cannot open source file "..."

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

cannot open source file "..."

Background:
C++运行环境:#VScode #MinGW-64 #Win10-64.

Error:
1: cannot open source file "string".
2: #include errors detected. Please update your includePath. IntelliSense features for this translation unit (C:CodeWillCppselectionSort.cpp) will be provided by the Tag Parser.
3: identifier "string" is undefined". (even have #include and using namespace std;)
4: string is not in std.

//其实这个Error很常见。目前理解是由于编译配置出现问题。
备注:对于Error2也可以在VSCode中File->Preferences->Settings在右侧的自定义配置中添加 "C_Cpp.intelliSenseEngine": "Tag Parser"。但不推荐这样做。

Solution steps:

  1. 在cmd中执行 gcc -v -E -x c++ -
  2. 复制输出结果中 #include <...> search starts here: 下的所有路径
  3. 在VSCode中 Ctrl+Shift+P, 输入Edit Configuration, 打开 c_cpp_properties.json,找到"name":"Win32"。
  4. 把第二步复制的路径添加到 c_cpp_properties.json 中的"name":"Win32"下"includePath"和的 "browse"的 "path"中,添加的路径要注有双引号。注意要保持原有顺序!路径中的 .. 不用修改。
    例如:
    "${workspaceRoot}",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/include/c++",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/include/c++/i686-w64-mingw32",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/include/c++/backward",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/include",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/include-fixed",
    "C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.2.0/../../../../i686-w64-mingw32/include"

        "defines": [
     "_DEBUG",
     "UNICODE",
     "_UNICODE",
     "__GNUC__=7",
     "__cdecl=__attribute__((__cdecl__))"
        ],
        "intelliSenseMode": "clang-x64",

以上内容也可延伸至如何用MinGW和VSCode正确配置一个C++开发环境,特别需要注意在VSCode中.vscode文件夹下的四个配置文件 c_cpp_properties.json, launch.json, settings.json, tasks.json 。

写这篇文章希望对使用C++/MinGW/VSCode初学者有所帮助,少走弯路。
相关知识还在摸索中,如有误导,欢迎各位大神留言更正,非常感谢!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/232531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号