【发布时间】:2016-08-06 22:25:00
【问题描述】:
我正在尝试使用 C++ 字符串类的统一初始化程序。下面是代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1 {"aaaaa"};
string str2 {5, 'a'};
string str3 (5, 'a');
cout << "str1: " << str1 << endl;
cout << "str2: " << str2 << endl;
cout << "str3: " << str3 << endl;
return 0;
}
输出将是:
str1: aaaaa
str2: a
str3: aaaaa
这让我摸不着头脑。为什么str2 无法达到str3 的预期结果?
【问题讨论】:
-
“统一”初始化...
标签: c++ string c++11 uniform-initialization list-initialization