C++ - Uniform initializer with std::string
问题 I am trying the uniform intializer with the string class of C++. Below is the code: #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; } The output would be: str1: aaaaa str2: a str3: aaaaa This made me scratched my head. Why str2 cannot achieved the desired result as str3 ? 回答1: std::string has