这个 C++ 错误 std::length_error 是什么意思

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1183700/
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 19:06:25  来源:igfitidea点击:

What is the meaning of this C++ Error std::length_error

c++stringruntime-error

提问by Janusz

While running my program I get this error:

在运行我的程序时,我收到此错误:

terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_S_create
Abort trap

I know that you can't do much without the code but I think that this error is too deep in the code to copy all of it. Maybe I can figure it out if I understand what this error means. Is this a sign for an issue with reading or writing at the wrong memory address?

我知道没有代码你就无能为力,但我认为这个错误在代码中太深了,无法复制所有内容。如果我理解这个错误的含义,也许我可以弄清楚。这是在错误的内存地址读取或写入问题的迹象吗?

Is there something I can do to get more information about the problem from my program?

我可以做些什么来从我的程序中获取有关问题的更多信息?

回答by Kevin Doyon

It means you tried to create a string bigger than std::string::max_size().

这意味着您试图创建一个大于 std::string::max_size() 的字符串。

http://msdn.microsoft.com/en-us/library/as4axahk(VS.80).aspx

http://msdn.microsoft.com/en-us/library/as4axahk(VS.80).aspx

An exception of type length_error Class is thrown when an operation produces a string with a length greater than the maximum size.

length_error 类型的异常 当操作产生长度大于最大大小的字符串时,会抛出类。

回答by Lukas Obermann

I know this is a old question but I just ran into the same issue. Using Linux with gcc.

我知道这是一个老问题,但我遇到了同样的问题。使用带有 gcc 的 Linux。

Disassembling the function showed a lot of jumps in the code, where the exception was thrown, which shouldn't be there. In the end, a Clean Build resolved the issue for me.

反汇编函数显示代码中有很多跳转,抛出异常的地方不应该存在。最后,Clean Build 为我解决了这个问题。

回答by Kouga

This is an error in debug mode with VS2005. When I change it to release mode, everything works.

这是 VS2005 调试模式下的错误。当我将其更改为发布模式时,一切正常。

Well, the vc debug runtime causes this, that's all.

好吧,vc 调试运行时导致了这个,仅此而已。