error: ISO C++ forbids comparison ... NEED HELP URGENT !!!
I've got this error while compiling one of my c++ progs:
Friends_command.cpp: In function `int main()': Friends_command.cpp:30: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:30:35: warning: character constant too long for its type Friends_command.cpp:30: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:93:16: warning: multi-character character constant Friends_command.cpp:93: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:93:35: warning: character constant too long for its type Friends_command.cpp:93: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:103:16: warning: multi-character character constant Friends_command.cpp:103: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:103:35: warning: character constant too long for its type Friends_command.cpp:103: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:109:16: warning: multi-character character constant Friends_command.cpp:109: error: ISO C++ forbids comparison between pointer and integer Friends_command.cpp:109:35: warning: character constant too long for its type Friends_command.cpp:109: error: ISO C++ forbids comparison between pointer and integer here is my code: Code:
#include<iostream> P.S: Sorry for the comlicated code .... :) |
A. Use std::string, not char arrays.
B. String use "" delimiters, not '' |
Ha !!! tuxdev thanks a lot !!! It worked - I'll keep that std::string in mind ...THANKS !!!
|
The string comparison still won't work even if you use double quotes. To compare strings using char arrays you have to use strcmp in string.h:
Code:
if (strcmp(command, "-e") == 0 || strmcp(command, "--enter") == 0) { and so on. This statement: Code:
if (command == "-e" || command == "--enter") { is comparing pointer values; command and "-e" are both pointers and very unlikely to be equal. |
Quote:
Code:
#include <string> PS To OP: you should use <cstdlib> instead of <stdlib.h> when using C++. |
The following should stop this code from compiling
Code:
... Please refrain from putting crap like Quote:
|
All times are GMT -5. The time now is 01:41 AM. |