ISO C++ forbids comparison between pointer and integer [-fpermissive]| [c++]

前端 未结 4 1914
感情败类
感情败类 2021-01-11 10:38

I am trying to compile the following code on Ubuntu (64-bit), with Code::Blocks 10.05 as IDE:

#include 
using namespace std;
int main() {
            


        
4条回答
  •  难免孤独
    2021-01-11 11:23

    This one is due to:

    if(a=='ab') , here, a is const char* type (ie : array of char)

    'ab' is a constant value,which isn't evaluated as string (because of single quote) but will be evaluated as integer.

    Since char is a primitive type inherited from C, no operator == is defined.

    the good code should be:

    if(strcmp(a,"ab")==0) , then you'll compare a const char* to another const char* using strcmp.

提交回复
热议问题