关于basic_string::_S_construct null not valid的解决方案

在刷OJ的时候碰到了这个问题:

struct Node{
    string str;
    int count;
};
Node node[100]={'\0',0};

我当时需要把count的值初始化为0(但其实你不初始化它默认的就是0,但我开始不知道)
然后出现了这个错误:

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

意思就是你的string指针指向了一个空值。
string类指针指向空值本来是很正常的,例如弄一个空指针:

string str=null;

但这里却不行,因为你是在结构体里默认的空指针,等于是在基类string的construct弄了个无效指针,导致运行中断,也就是RE。

猜你喜欢

转载自blog.csdn.net/csustudent007/article/details/80850982
今日推荐