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

后端 未结 6 531
野性不改
野性不改 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 20:59

    In line 2, there's a std::string involved (name). There are operations defined for char[] + std::string, std::string + char[], etc. "Hello " + name gives a std::string, which is added to " you are ", giving another string, etc.

    In line 3, you're saying

    char[] + char[] + char[]
    

    and you can't just add arrays to each other.

提交回复
热议问题