Feb 18, 2012 at 9:51pm UTC
Is the output defined?
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a = "Hello, Internet!" ;
cout << a.size() << endl;
a[5] = '\0' ;
cout << a.size() << endl;
}
16
16
And furthermore, is it safe to do this?
Last edited on Feb 18, 2012 at 9:52pm UTC
Feb 18, 2012 at 10:23pm UTC
Cool, I wasn't sure if the standard maintained that implementations couldn't use null terminated implementations. Thanks!
Last edited on Feb 18, 2012 at 10:23pm UTC
Feb 18, 2012 at 10:37pm UTC
I mean, I wasn't sure if the C++ language standard stated that std::string implementations can't just be wrappers for null-terminated character arrays.