Code Fix

初級error: ISO C++ forbids comparison between pointer and integer の原因と直し方 › パターン3

error: ISO C++ forbids comparison between pointer and integer の原因と直し方

int型の変数をダブルクォートの文字列リテラル(例: "20")と== で比較しようとしたときに出るエラーです。

 1  #include <iostream>
 2  int main() {
 3      int level = 1;
 4      if (level == ___) {
                      ^
 5          std::cout << "beginner" << std::endl;
 6      }
 7      return 0;
 8  }
main.cpp:4:15: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

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

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

error: ISO C++ forbids comparison between pointer and integer の原因と直し方

文字列リテラルはconst char*型であり、int型とは根本的に比較できません。

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

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