简体   繁体   English

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?

I remember all the hassle it used to be processing strings and ensuring that a newline was or wasn't appended before EOF. 我记得所有以前处理字符串和确保在EOF之前添加或不添加换行符的麻烦。

Now as my error references interop I am wondering if this is normal behaviour still or just an interop 'enhancement', here's my error: 现在,当我的错误引用互操作时,我想知道这是否仍然是正常行为,或者仅仅是互操作“增强”,这是我的错误:

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.

Not terribly helpful. 不是很有帮助。 If I must terminate with a new line that's cool but is the std library so far optimized that it can't handle the odd EOF? 如果我必须以凉爽的新行终止,但到目前为止std库是否已优化,无法处理奇数EOF?

I think it should at least throw an exception that unwinds the stack to find a handler or terminate, but the stack is still deeply inside the std:: functions. 我认为它至少应该引发一个异常,该异常会使堆栈松开以查找处理程序或终止,但是堆栈仍深藏在std ::函数内部。 Is this just a feature of the debug flags in VS? 这仅仅是VS中的调试标志的功能吗?

EDIT 编辑

    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.

I have no idea how the SEHException is related, but is your input in the format of: 我不知道SEHException是如何关联的,但是您的输入格式为:

std::istream& in;
std::string line;
while (std::getline(in, line)) {
    //stuff
}

That's the safest method for reading in line by line I've ever come across. 这是我遇到过的最安全的逐行阅读方法。

I think it should at least throw an exception that unwinds the stack to find a handler or terminate
§ 15.3 (From Feb 2011 C++ draft) §15.3(从2011年2月起,C ++起草)

If no matching handler is found, the function std::terminate() is called; 如果找不到匹配的处理程序,则调用函数std :: terminate(); whether or not the stack is unwound before this call to std::terminate() is implementation-defined (15.5.1). 调用std :: terminate()之前是否取消堆栈的堆栈是实现定义的(15.5.1)。

This means the debugger was right about to crash your entire program (probably without unwinding), but decided to be nice and break and show you what was happening first. 这意味着调试器将崩溃整个程序(可能不会崩溃)是正确的 ,但是决定保持友好并中断并向您展示发生了什么。 You'll have to step through the stack to see exactly why Windows decided to throw an SEHException . 您必须逐步检查堆栈,才能确切了解Windows为什么决定抛出SEHException According to some random web crawling, an SEH can be fired by the standard library when you access unallocated memory, dereference NULL pointers, run out of memory, or other situations. 根据一些随机的Web爬网,当您访问未分配的内存,取消引用NULL指针,内存不足或其他情况时,标准库可以触发SEH。 You'll also want to try to look at the members of the SEHException object, to see what the status and message are. 您还需要尝试查看SEHException对象的成员,以查看状态和消息是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM