初級 › error: ISO C++ forbids comparison between pointer and integer の原因と直し方 › パターン2
error: ISO C++ forbids comparison between pointer and integer の原因と直し方
int型の変数をダブルクォートの文字列リテラル(例: "20")と== で比較しようとしたときに出るエラーです。
1 #include <iostream> 2 int main() { 3 int code = 7; 4 if (code == ___) { ^ 5 std::cout << "ok" << std::endl; 6 } 7 return 0; 8 }
main.cpp:4:14: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
空欄を埋めてコンパイル・実行を通す
見た目が同じ「7」でも、ダブルクォートで囲むと文字列(ポインタ)になり、int型とは比較できない別の型になります。
次の問題