'+' cannot add two pointers error

前端 未结 3 1268
野性不改
野性不改 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:38

    "chicken " and "nuggets" are literal C-string and not std::string.

    You may concatenate directly with:

    std::string c = "chicken " "nuggets";
    

    Since C++14, you may add suffix s to have string

    using namespace std::string_literals;
    std::string c = "chicken "s + "nuggets"s;
    

提交回复
热议问题