【结束符】
1. string以‘\0’结束
string str="abcdef";
if(str[6]=='\0'){
cout<<"yes"<<endl;
}
输出:
yes
2.修改'\0'位置
string str="abcdef";
str[3]='\0';
if(str[3]=='\0'){
cout<<"yes"<<endl;
}
cout<<str<<endl;
输出:
yes
abc_ef
疑问:输出为什么不是abc,而是abc_ef ????
3.可以通过char str[N]来实现
char str[7]="abcdef";
cout << str << endl;
if (str[6] == '\0')
cout << "yes" << endl;
str[3] = '\0';
cout << str << endl;
输出:
abcdef
yes
abc
--------------------------------------------------------------------------------------------------------------------------------------------------
【】
--------------------------------------------------------------------------------------------------------------------------------------------------
(个人笔记,欢迎指正)