string对象初始化出错
mylq 2016-06-13 12:27:24 我想将string对象初始化为空,string poing=NULL;
编译可以通过,但是无法运行,报错:
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid
查阅得std::string 的构造函数需要的是一个 c 风格的字符串指针(要求以字符 null 结尾),NULL好像是0吧,一个宏定义,用来防止指针悬空,一般用来和指针做比较或者赋给指针。
既然可以赋给指针,而string构造函数也需要指针,为什么不能直接用来初始化?