#include<iostream>
#include<string>
using namespace std;
int main(){
string i = "abc\0defg";
cout<<i<<endl;
// This prints "abc"
string x = "abcdefg";
x[3]='\0';
cout << x << endl;
// This prints "abcefg"
}
I know that the instance i
of the C++ String class doesn't interpret \0
as the end of a string. Why the string i
left out everything after the \0
? What's the difference between string i
and x
?