初級 › error: ISO C++ forbids comparison between pointer and integer の原因と直し方 › パターン1
error: ISO C++ forbids comparison between pointer and integer の原因と直し方
int型の変数をダブルクォートの文字列リテラル(例: "20")と== で比較しようとしたときに出るエラーです。
1 #include <iostream> 2 int main() { 3 int age = 20; 4 if (age == ____) { ^ 5 std::cout << "match" << std::endl; 6 } else { 7 std::cout << "no match" << std::endl; 8 } 9 return 0; 10 }
main.cpp:4:13: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
空欄を埋めてコンパイル・実行を通す
"20"はconst char*型(文字列へのポインタ)であり、int型のageとは比べられません。数値と比較するには数値リテラルの20を使います。
次の問題