string对象和字符字面值及字符串字面值在同一语句中相加使用时,必须确保加法运算符两侧运算对象至少一个是string。
string str1=“hello”;
string str2=str1+“,”+“world”;正确,因为str1+","返回string对象。
c++字符串字面值,例如"helloworld"不是标准库类型string的对象。
字符串字面值与string是不同类型。
string str=“hello”;
sizeof(“hello”);输出为6
strlen(“hello”);输出为5
sizeof(str);输出为28,string类型的打小
strlen(str);报错不能将string转换成const char*
str.size();输出为5