有人能解释下面例子中用双花括号和单花括号初始化之间的行为差异吗?
代码#1:
vector<string> v = {"a", "b"};
string c(v[0] + v[1]);
cout << "c = " << c;
cout << "c.c_str() = " << c.c_str();
Run Code Online (Sandbox Code Playgroud)
输出#1:
c = ab
c.c_str() = ab
Run Code Online (Sandbox Code Playgroud)
代码#2:
vector<string> v = {{"a", "b"}};
string c(v[0] + v[1]);
cout << "c = " << c;
cout << "c.c_str() = " << c.c_str();
Run Code Online (Sandbox Code Playgroud)
输出#2:
c = a\acke?Z\
c.c_str() = a
Run Code Online (Sandbox Code Playgroud)