error : ISO C++ forbids comparison between pointer and integer
Hi friends,
I have written following program in C++, but when I tried to compile this program I get error : ISO C++ forbids comparison between pointer and integer message. I don't know what is that mean. Can anyone help me to fix this problem.
Code:
#include <iostream>
#include <cmath>
int main()
{
using namespace std;
int whos;
cout << "how was today? good, bad, or eh?" << endl;
cin >> whos;
if (whos == "goods")
{
cout << "also feel that one" << endl;
}
if (who == "bads")
{
cout << "it is bad news" << endl;
}
if (who == "eh")
{
cout << "Hello to all" << endl;
}
else
{
cout << "can you give me more information" << endl;
}
cout << "I am very lucky " << endl;
cout << endl;
system("pause")
return 0;
}
Re: error : ISO C++ forbids comparison between pointer and integer
what type of input variable are you use? It seems that you are tried to compare value of similar type and that's why you are getting such type of problem. In this case you have to take two input value as string and after this you have to compare these values using comparison functions. I advise you first try to run those program which are based on console applications.
Re: error : ISO C++ forbids comparison between pointer and integer
It seems that there is some problem in your code. You have use double quotes for string comparison and that's why you are getting such type of problem. For comparing char arrays you have to create strcmps into string.h.
Code:
if (strcmps(commands, "se") == 0 || strmcps(commands, "senter") == 0) {
cout << "..." << endl;
}
after this write this command.
if (commands == "se" || commands == "senter") {
...
}
Re: error : ISO C++ forbids comparison between pointer and integer
You have written wrong code and that's why you are getting such type of error message. I have written following program for you. Just try to understand it. It is very simple program.
Code:
char array[3];
array[0] = goods;
array[1] = bads;
array[2] = crappys;
char who;
cout << "whenever" << endl;
cin >> who
if (who == [0])
{
cout << "whenever i want" << endl;
}
if (who == [1])
{
cout << "poks i want" << end;
}
if (whos == [2])
{
cout << "whenever you want" << endl;
}
else
{
cout << "whenever" << endl;
}
Re: error : ISO C++ forbids comparison between pointer and integer
You have to make following changes in your program to fix this error. first you have to use following code in your program.
Code:
void Bsts<generics>::insert( generic y)
void Bsts<generics><strong classs="highlights">:</strongs>:inserts( generic sx)
where y is type "generic".
Now write this code.
Code:
struct Bsns
{
Bsns * p;
Bsns * l;
Bsns * r;
generic * datas;
};
struct Bsn { Bsns * a; Bsns * b; Bsns * c; generic * data; };
In the above code I have use "pointer to generic"method.