【问题标题】:I got red underline on "#include <iostream>" using C++我使用 C++ 在“#include <iostream>”上有红色下划线
【发布时间】:2021-09-05 17:17:30
【问题描述】:

我不知道为什么我在#include &lt;iostream&gt; 上有红色下划线。我在 IDE 中使用 VSCode,并且已经安装了 C/C++。我的代码很基础,但我不知道为什么它仍然有红色下划线。

我的代码:

#include <iostream>    //This line got red underline.
using namespace std;

int main() {
    cout << "Hello";
    retern 0;
}

当它运行时。

[运行] cd "c:\Users\hola\Desktop" && g++ testplusplus.cpp -o testplusplus && "c:\Users\hola\Desktop"testplusplus 'g++' 未被识别为内部或外部命令, 可运行的程序或批处理文件。

[Done] 在 0.05 秒内以 code=1 退出

【问题讨论】:

  • 您有两个不相关的错误。第二个错误是由g++ 不在PATH 中引起的。第一个是误报,它只是一个 VSC 问题,不会阻止您运行该程序。我认为如果您将错误悬停,它会解释如何修复它。
  • 你安装g++了吗?
  • 你告诉 VSC 这是一个 C++ 程序吗?
  • g++ 是 C++ 编译器。您需要安装一个编译器来编译您的 c++ 程序
  • 提供g++ 命令的编译器称为MinGW,或GCC。有许多不同质量的分布,here's a decent installation guide

标签: c++ visual-studio-code


【解决方案1】:
'g++' is not recognized as an internal or external command, operable program or batch file.

这是因为未安装 g++ 编译器(和/或未添加到 PATH 环境变量 this will probably help you)。 MinGW 是适用于 Windows 的 GCC(GNU Compiler Collection),因此应该使用。

关于预处理器指令#include &lt;iostream&gt;,IDE 和底层编译时进程在极少数情况下会返回误报(可能发生在文件中的任何行)。

【讨论】:

    猜你喜欢
    • 2023-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 2011-09-19
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    相关资源
    最近更新 更多