C++ 如何避免错误:在抛出 'std::logic_error' what() 实例后调用终止:basic_string::_S_construct null not valid

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11705886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:26:24  来源:igfitidea点击:

How to avoid the error: terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_S_construct null not valid

c++libstdc++

提问by Czon

if(player!=NULL)
    player->shuffled();

I do such things to avoid passing a null reference to a string constructor, but when compiling it still comes to error.

我这样做是为了避免将空引用传递给字符串构造函数,但是在编译时它仍然会出错。

回答by Dave S

Somewhere, somehow, you're calling the std::stringconstructor with the const char*value NULL.

在某处,不知何故,您正在std::string使用const char*值 NULL调用构造函数。

To avoid the problem. Don't do that.

以免出现问题。不要那样做。