. Advertisement .
..3..
. Advertisement .
..4..
Recently, I ran some of my cpp code, and it gave the warning text:
error: ISO C++ forbids comparison between pointer and integer
While searching, I realized that some people added some command lines in my sample above. But I don’t think it is the best way to correct the problem – iso c++ forbids comparison between pointer and integer How would you explain this trouble? or Is there a better way? Below is the detail of the command that I used:
#include <iostream>
#include <string>
using namespace std;
bool accept()
{
cout << "Do you want to proceed (y or n)?\n";
char answer;
cin >> answer;
if (answer == "y") return true;
return false;
}
The cause: The reason of this error is:
Because single quotes represents a
char
constant, not double quotes.Solution: There are two ways to fix this error:
1, You can use
string answer;
instead ofchar
2, Another way is fix as below:
(Remember single quotes instead of double, represents a
char
constant)It is necessary to convert double quotation marks into singles. ie.
if (answer == 'y')
returnstrue
;Here is some info on String Literals in C++: http://msdn.microsoft.com/en-us/library/69ze775t%28VS.80%29.aspx