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