Code Fix

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

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

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

 1  #include <iostream>
 2  int main() {
 3      int width = 10;
 4      int height = 20;
 5      std::cout << (width * _______) << std::endl;
                                 ^
 6      return 0;
 7  }
main.cpp:5:27: error: 'hight' was not declared in this scope; did you mean 'height'?

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

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

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

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

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

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