Error: invalid operands of types ‘const char [35]’ and ‘const char [2]’ to binary ‘operator+’

后端 未结 6 538
野性不改
野性不改 2020-11-28 20:36

At the top of my file I have

#define AGE \"42\"

Later in the file I use ID multiple times including some lines that look like



        
6条回答
  •  星月不相逢
    2020-11-28 21:20

    In this particular case, an even simpler fix would be to just get rid of the "+" all together because AGE is a string literal and what comes before and after are also string literals. You could write line 3 as:

    str += "Do you feel " AGE " years old?";

    This is because most C/C++ compilers will concatenate string literals automatically. The above is equivalent to:

    str += "Do you feel " "42" " years old?";

    which the compiler will convert to:

    str += "Do you feel 42 years old?";

提交回复
热议问题