初級 › error: 'cout' is not a member of 'std' の原因と直し方 › パターン1
error: 'cout' is not a member of 'std' の原因と直し方
#include <iostream> を書き忘れたまま std::cout や std::endl を使ったときに出るエラーです。
1 ___________________ ^ 2 int main() { 3 std::cout << "hello" << std::endl; 4 return 0; 5 }
main.cpp:3:10: error: 'cout' is not a member of 'std'
空欄を埋めてコンパイル・実行を通す
std::coutを使うにはiostreamヘッダのインクロードが必要です。std名前空間自体は存在しても、coutの宣言はiostreamの中にあるため、インクルードを忘れるとコンパイラは見つけられません。
次の問題