簡體   English   中英

在終端中運行 c++ 並得到“致命錯誤:找不到'iostream'文件”

[英]Running c++ in terminal and got “fatal error: 'iostream' file not found”

我對 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 代碼中運行腳本時,它工作得很好。

我知道還有其他幾個類似的問題被問到,但我不明白他們是如何解決這個問題的。 誰能給我一些分步說明? 太感謝了 !

事實證明,只需在終端中添加gcc test.cpp -lstdc++解決問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM