string str4;
str4.assign("Hello C++");
cout << "str4 = " << str4 << endl;
string str5("Hello C++", 5);
cout << "str5 = " << str5 << endl;
这段运行的结果str5是Hello
而把str5改成string str5(str4, 5);为什么输出的是 “C++”?就相当于功能反过来了?
string str4;
str4.assign("Hello C++");
cout << "str4 = " << str4 << endl;
string str5("Hello C++", 5);
cout << "str5 = " << str5 << endl;
这段运行的结果str5是Hello
而把str5改成string str5(str4, 5);为什么输出的是 “C++”?就相当于功能反过来了?
因为它调用的是
basic_string( const basic_string& other,
size_type pos,
const Allocator& alloc = Allocator() );
这个构造函数第二个参数指的是从何处复制