代码:
#include <stdio.h>
#include <string>
int main(int argc, char* argv[])
{
std::string str(NULL);
return 0;
}
linux下运行结果:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_M_construct null not valid
已放弃(吐核)
所以在给string对象赋值时,先校验源对象是否等于NULL很重要;