Code Fix

初級error: 'x' was not declared in this scope の原因と直し方 › パターン1

error: 'x' was not declared in this scope の原因と直し方

宣言していない変数を使ったときに出るエラーです。

 1  #include <iostream>
 2  int main() {
 3      int total = 5;
 4      std::cout << ______ << std::endl;
                        ^
 5      return 0;
 6  }
main.cpp:4:18: error: 'toal' was not declared in this scope; did you mean 'total'?

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

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

error: 'x' was not declared in this scope の原因と直し方

多くの場合はタイプミスで、g++は似た名前の宣言済み変数があれば「did you mean 'total'?」のように候補を提案してくれます。

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

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