关于streambuf溢出功能的查询
仔细阅读溢出函数文档。我发现溢出有以下作为返回值。
返回值:
不同于 EOF(或其他特征的 Traits::eof())的值表示成功。
如果函数失败,则返回 EOF(或用于其他特征的 Traits::eof())或引发异常。
来源:“http://www.cplusplus.com/reference/iostream/streambuf/溢出/”
谁能告诉我溢出函数在哪个场景中会通过异常? 任何帮助将不胜感激
Going thorugh overflow function documentation. I found overflow has following as return values.
Return Value:
A value different than EOF (or traits::eof() for other traits) signals success.
If the function fails, either EOF (or traits::eof() for other traits) is returned or an exception is thrown.
source :"http://www.cplusplus.com/reference/iostream/streambuf/overflow/"
Can anyone please tell me in which sceanrios is overflow function going to through an exception?
Any help will be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Streambuf 是流的底层存储或通信通道的抽象。由于存储或通道失败的任何原因,overflow() 函数都可能失败。例如,磁盘文件的磁盘错误、套接字连接断开等。
Streambuf is abstraction for stream's underlying storage or communication channel. The overflow() function can fail for any reasons the storage or channel can fail. E.g. disk error for disk files, broken connection for sockets etc.
尽管 wilx 详细说明了失败 (
EOF
) 条件,但异常条件可以是以下任一条件:http://www.aoc.nrao.edu/php/tjuerges/ALMA/STL/html-3.4.6/classstd_1_1exception.html (你能猜出是哪一个吗?:) - 但如果你正在编写自己的输出流或其他东西,它应该(显然)是std::overflow_error
。Although wilx detailed the fail (
EOF
) condition, the exception condition can be either one of these: http://www.aoc.nrao.edu/php/tjuerges/ALMA/STL/html-3.4.6/classstd_1_1exception.html (can you guess which one? :) -- but it should (obviously) bestd::overflow_error
if you're writing your own output stream or something.在我的有问题的场景中,它失败了,因为它没有跳转下一个地址(setp 调用递增 0),因此重试使用相同的内存区域并给出分段错误。
In my problematic scenario it was faling because it was not jumping the next address(setp calls was incrementating by 0) so retrying to use the same memory region and was giving segmentation fault.