Code Fix

初級 › 'cout' was not declared エラー(std::忘れ)の原因 › パターン3

'cout' was not declared エラー(std::忘れ)の原因

#include <iostream> はしているのに、std::を付けずにcoutやendlをそのまま使ったときに出るエラーです。

 1  #include <iostream>
 2  int main() {
 3      std::cout << "score: " << 90 ____________;
                                           ^
 4      return 0;
 5  }
main.cpp:3:37: error: 'endl' was not declared in this scope; did you mean 'std::endl'?

空欄を埋めてコンパイル・実行を通す

広告
広告スロット(未設定)

'cout' was not declared エラー(std::忘れ)の原因

C++では標準ライブラリの名前はstd名前空間の中にあり、省略するにはusing宣言が必要です。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)