Visual c++, std和getline(ifstream, string), EOF在std栈内抛出和中断,这正
Visual C++, std and getline(ifstream, string), EOF throws and breaks inside the std stack, is this normal?
我记得它过去处理字符串和确保在EOF之前添加换行符时所遇到的所有麻烦。
现在我的错误引用互操作,我想知道这是正常的行为仍然或只是一个互操作的"增强",这是我的错误:
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in blah.exe
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in blah.exe
Additional information: External component has thrown an exception.
不是很有帮助。如果我必须以新行结束,这很酷,但是std库是否已经优化到不能处理奇怪的EOF?
我认为它至少应该抛出一个异常来展开堆栈以找到一个处理程序或终止,但是堆栈仍然在std::函数的深处。这只是一个功能的调试标志在VS?
编辑
ifstream is("MyfileorSummat.txt");
string line;
while (getline(is, line)) { //But when is reads last line @#&#@, it breaks, in the middle of a chain of std calls.
我不知道SEHException
是如何相关的,但是您的输入格式是:
std::istream& in;
std::string line;
while (std::getline(in, line)) {
//stuff
}
这是我所见过的最安全的逐行阅读方法。
I think it should at least throw an exception that unwinds the stack to find a handler or terminate
§15.3(自2011年2月c++草案)
如果没有找到匹配的处理程序,则调用std::terminate()函数;在调用std::terminate()之前是否展开堆栈是由实现定义的(15.5.1)。
这意味着调试器对崩溃整个程序的判断是正确的(可能没有展开),但是为了让您看到发生了什么,调试器决定先中断。你必须通过堆栈一步,看看为什么Windows决定抛出一个SEHException
。根据一些随机的web抓取,当您访问未分配的内存、解引用NULL指针、内存耗尽或其他情况时,标准库可以触发SEH。您还需要尝试查看SEHException对象的成员,看看状态和消息是什么。
相关文章:
- 使用std::multimap迭代器创建std::list
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- 来自 std::list 的迭代器 .end() 按预期返回"0xcdcdcdcdcdcdcdcd"但 .begin()
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 从持续时间构造std::chrono::system_clock::time_point
- std::具有相同基类的类的变体
- std::向量与传递值的动态数组
- 使用std::vector的OpenCL矩阵乘法
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- std::condition_variable::wait()如何评估给定的谓词
- <T> 当 std::atomic<T>::is_always_lock_free 为假时,中断是否安全?
- 重载运算符 = 中断 std::sort
- 使用 std::weak_ptr 和别名构造函数中断循环引用:声音或有问题
- 如何中断其他 std::threads c++
- 在std::for_each的执行过程中累积结果,该异常被中断
- 如何解决错误 'std::out_of_range' what(): _M_range_check ,向量将接受值,直到被告知中断
- Visual c++, std和getline(ifstream, string), EOF在std栈内抛出和中断,这正
- std::lock_guard可以被中断吗?
- 如果stdin被另一个进程的管道替换,Std::getline将中断