you use string type defined in namespace std? i make a test,it runs properly. #include<iostream> #include<string> using namespace std;void main() { string s1="hello\0"; string s2=" world!"; string s3 = s1+s2; cout<<s3<<endl; }
this is also right: string s1="hello\0"; string s2=" world!"; string s3 = s1+s2; s1+=" world"; cout<<s1<<endl; ____________________________ s1:hello world
i make a test,it runs properly.
#include<iostream>
#include<string>
using namespace std;void main()
{
string s1="hello\0";
string s2=" world!";
string s3 = s1+s2;
cout<<s3<<endl;
}
string s1="hello\0";
string s2=" world!";
string s3 = s1+s2;
s1+=" world";
cout<<s1<<endl;
____________________________
s1:hello world