Class and Object

Hi!
I am want to compare two values. First value is an input from user. which i stored in object variable. Second value is predefined. When i try to compare it. Compiler generate a error saying "ISO c++ forbid comparison between pointer and integer value".
How can i solve it?

Code:

class pass{
private:
char in[10]; // To store command
int rawpass; // To store value
public:
void inp();
char dec();
};

void pass::inp()
{
cout<<"Type 'help' for Help"<<endl;
cin>>in;
cin.ignore('\r');
}

char pass::dec()
{
if(in=='help')
{
cout<<"generate";
cout<<": This command is used to generate a random password";
cout<<endl<<"encrypt";
cout<<": This command is used to encrypt a password";
cout<<endl<<"decrypt: This command is used to decrypt a password";
cout<<endl<<"intro: This command is used to provide a brife introduction about software";
cout<<endl<<"trouble: This command is used for trouble shooting";
cout<<endl<<"credit: This command is used to display information abot the develpor";
cin>>in;
}

else if(in=='generate')
{
cout<<"Genrating password"<<endl;
return 'g';
}

else if(in=='encrypt')
{
cout<<"Encrypting"<<endl;
return 'e';
}

else if(in=='decrypt')
{
cout<<"Decrypting"<<endl;
return 'd';
}

else if(in=='into')
{
cout<<"Intoduction"<<endl;
return 'i';
}

else if(in=='trouble')
{
cout<<"Trouble shooting"<<endl;
return 't';
}

else if(in=='credit')
{
cout<<"Credit"<<endl;
return 'c';
}

else;
cout<<"Something went wrong"<<endl;
cout<<"Type 'trouble' for trouble shooting"<<endl;
cout<<"Type 'help' for Help"<<endl;
void inp();
}

Last edited on
My compiler wrote:
warning: multi-character character constant [-Wmultichar]

Single quotes (') are for character literals. For strings you need to use double quotes (").

To compare two C strings (null-terminated character arrays) you can use the std::strcmp function.

 
if(strcmp(in, "help") == 0)

http://en.cppreference.com/w/cpp/string/byte/strcmp

Or, if you use std::string to store your strings, you can use the == operator to compare them.

http://www.cplusplus.com/reference/string/string/
Last edited on
Topic archived. No new replies allowed.