7 Feb
2014
7 Feb
'14
12:42 p.m.
Hi,
It is good we are slowly moving to using std::string... but mixing it with char* can be tricky. In particular, I've seen several bugs recently when char* is a null pointer. You cannot initialize a std::string with a null pointer. You will get at run time:
terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid
I don't know what "best practice" is but this seems to work:
std::string my_string = c_string ? c_string : "";
You can also not compare a std::string to a null pointer.
Tav