关于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。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值