In C++ 03, non è stato necessario memorizzare una stringa std :: string in un buffer con terminazione NUL, ma se si chiamasse c_str()
, si restituirebbe un puntatore a un buffer con terminazione NUL. Tale buffer potrebbe essere legalmente creato e/o terminato all'interno della chiamata c_str()
.
In C++ 11, tutti std::string
istanze vengono terminati, così data()
affronta anche un buffer NUL-terminato, e anche s[s.size()]
ha un significato ben definito che restituisce un riferimento alla NUL terminazione.
fonte
2013-07-22 05:43:21
'null'! =' NUL'! – trojanfoe
Correlati: http://stackoverflow.com/questions/6077189/will-stdstring-always-be-null-terminated-in-c11 – jogojapan