Code Fix

初級 › error: expected '}' at end of input の原因と直し方 › パターン4

error: expected '}' at end of input の原因と直し方

波括弧{}の対応が崩れ、閉じ忘れがあるときに出るエラーです。

 1  #include <iostream>
 2  int main() {
 3      int x = 5;
 4      if (x > 0) {
 5          std::cout << "positive" << std::endl;
 6      _
        ^
 7      return 0;
 8  }
main.cpp:8:2: error: expected '}' at end of input

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

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

error: expected '}' at end of input の原因と直し方

ファイルの終わりまで読んでもブロックが閉じられないため、末尾でエラーになります。

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

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