在给string char*赋完之后,如果把其中的某一位变为'\0',输出该字符串的时候,该位后面的字符依然能显示出来。
往string中添加‘\0'时,string的长度增加,但添加字符串“\0”时,string长度不增加。
#include <iostream>
#include<string>
using namespace std;
int main()
{
int i;
char* c="abcde";
string str=c;
cout<<"str:"<<str<<endl;
str[2]='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+='\0';
str+='\0';
str+='\0';
str+="\0";
str+="\0";
str+="\0";
str+="\0";
cout<<"str:"<<str<<endl;
cout<<"str.length:"<<str.length()<<endl;
return 0;
}