Why setting null in the middle of std string doesn't have any effect
Consider #include <string> #include <iostream> int main() { /* hello 5 hel 3 */ char a[] = "hello"; std::cout << a << std::endl; std::cout << strlen(a) << std::endl; a[3] = 0; std::cout << a << std::endl; std::cout << strlen(a) << std::endl; /* hello 5 hel o 5 */ std::string b = "hello"; std::cout << b << std::endl; std::cout << b.length() << std::endl; b[3] = 0; std::cout << b << std::endl; std::cout << b.length() << std::endl; getchar(); } I expect std::string will behave identical to char array a. That's it, insert null character in the middle of the string, will "terminate" the string.