string类构造函数匹配问题
string(const char *s,size_t n); // 将string对象初始化为s指向的地址后n字节的内容。
在对s5的操作中,使用的构造函数和s3的不一样,使用的构造函数为:string(const char *s,size_t n); // 将string对象初始化为s指向的地址后n字节的内容。
构造函数的重载,默认匹配重合度更高的
void testTwo3()
{
string s1 = "hello ! my name is liu xiang";
string s2(s1, 2, 6);
string s3(s1, 2);
cout << "s2 = " << s2 << endl;
cout << "s3 = " << s3 << endl;
string s4("hello ! my name is liu xiang", 2, 4);
string s5("hello ! my name is liu xiang", 2);
cout << "s4 = " << s4 << endl;
cout << "s5 = " << s5 << endl;
cout << "在对s5的操作中,使用的构造函数和s3的不一样,使用的构造函数为:string(const char *s,size_t n); // 将string对象初始化为s指向的地址后n字节的内容。" << endl;
}