提问者:小点点

在终端中运行C++,得到“致命错误:找不到'iostream'文件”


我对C++很陌生,当我运行脚本时

#include <iostream>
using namespace std;

int main() {
  cout << "Hello World!" << endl;
  cout << "Another message";
  return 0;
}

在终端cpp test.cpp中,我得到了以下错误消息:

test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.

我在Mac上使用clang作为编译器。 文本编辑器是VS Studio代码。 奇怪的是,当我通过扩展“code Runner”在VS Studio代码中运行脚本时,它工作得很好。

我知道还有其他几个类似的问题正在被问,但我无法理解他们是如何解决这个问题的。 谁能给我一些循序渐进的指示? 太谢谢你了!


共1个答案

匿名用户

原来,只需在终端中添加gcc test.cpp-lstdc++就解决了这个问题。

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(终端|中|运行|c++|致命|找不到|iostream|文件)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?