'+' cannot add two pointers error

前端 未结 3 1298
野性不改
野性不改 2021-01-21 00:14

I can do what the following code shows:

std::string a = \"chicken \";
std::string b = \"nuggets\";
std::string c = a + b;

However, this fails:<

3条回答
  •  我在风中等你
    2021-01-21 00:28

    "chicken " and "nuggets" are not of type std::string but are const char[]. As such even though you want to assign the concatenation to a string they types don't have an operator +. You could solve this using:

    std::string c = std::string("chicken ") + "nuggets";
    

提交回复
热议问题