爲什麼我不能比較UserInput[i]
到"*"
?編譯器說「ISO C++禁止指針和整數之間的比較」。整數在哪裏?我在該行看到的唯一一個是i
,它用於定位特定字符。爲什麼我不能將char與「*」進行比較?
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main(){
char UserInput[4] = "2*3";
for (int i=0; i< strlen(UserInput); i++){
if(UserInput[i] == "*"){
cout<<"There is multiplication Involved \n";
}
}
return 0;
}
的不要使用C風格的字符串。 'std :: string'是你的朋友。 –
這個縮進只是......令人討厭的。 –