我正在使用其中一个相关问题中使用的表单。唯一的问题是,我一直在文件的最后。C++ EOF Getline错误
该文件是一个fstream和str是一个字符串。
未处理的异常 微软C++异常:性病::的ios_base ::失败
while (getline(file, str)) {}
if (cin.bad()) { // IO error } else if (!cin.eof()) { // format error (not possible with getline but possible with operator>>) } else { // format error (not possible with getline but possible with operator>>) // or end of file (can't make the difference) }
谢谢,没有注意到,一些打开文件例外示例代码了, raw_data.exceptions(ifstream的:: failbit | ifstream的:: badbit); – Roo 2010-02-27 09:38:19