エラー:「cout」はこのスコープで宣言されていません
Error Coutwas Not Declared This Scope
LinuxでのC ++コンパイルエラーの原因の分析
プログラム:
#include int main() { cout << 'hello world' << endl }
コンパイルエラー:
$ g ++ s.cpp -o s.out
s.cpp:関数内 'int main(int、char **)':
s.cpp:12:エラー: 'cout'はこのスコープで宣言されていません
s.cpp:12:エラー: 'endl'はこのスコープで宣言されていません
理由:
C ++ 1998では、「std :: cout」および「std :: endl」形式を使用するか、名前空間stdを使用して、coutおよびendlを呼び出す必要があります。
変更後:
#include int main() { std::cout << 'hello world' << std::endl }
または
#include using namespace std int main(int argc, char *argv[]) { cout << 'hello world' << endl }
コンパイルして合格します。