int i = 1;
string s;//空字符串
if (s.empty())
{
cout << "字符串为空" << endl;//字符串确实为空
cout << s.size() << endl;//size 为0;
}
cout << i << endl;
cout << s[0] << i<<endl;//会打印一个空格
//cout<<s[1]<<endl;运行时出错
int i = 1;
string s="11";
if (s.empty())
{
cout << "字符串为空" << endl;
cout << s.size() << endl;
}
cout << s[0]<<endl;
cout << s[1] << endl;
cout << s[2] << i << endl;
可见字符串末尾默认有一个空字符,未初始化的空字符串也默认有这个空字符,这个空字符不算在size()中,