- 代码:
#include<string>
#include<iostream>
using namespace std;
int main()
{
string a = "12345678\0\0\0\0\0 3";
a[2] = '\0';
cout << a << endl;
a = "uiop\0op";
cout << a;
}
- 结果:
12 45678
uiop
-
结果很奇特,需要注意一下
#include<string>
#include<iostream>
using namespace std;
int main()
{
string a = "12345678\0\0\0\0\0 3";
a[2] = '\0';
cout << a << endl;
a = "uiop\0op";
cout << a;
}
12 45678
uiop