【发布时间】:2018-06-15 05:32:08
【问题描述】:
在s6 和s7 的定义中,s6 中的每个 + 怎么会有一个字符串,为什么s7 中还没有?
#include <string>
using std::string;
int main()
{
string s1 = "hello", s2 = "world";
string s3 = s1 + ", " + s2 + '\n';
string s4 = s1 + ", "; // ok: adding a string and a literal
string s5 = "hello" + ", "; // error: no string operand
string s6 = s1 + ", " + "world"; // ok: each + has a string operand
string s7 = "hello" + ", " + s2; // error: can't add string literal
}
【问题讨论】: