如何检测C中的空文件?
发布时间:2020-12-16 10:10:28 所属栏目:百科 来源:网络整理
导读:参见英文答案 Checking for an empty file in C++ ????????????????????????????????????8个 我正在尝试使用eof和peek,但两者似乎都没有给我正确的答案. if (inputFile.fail()) //check for file open failure{ cout "Error opening file" endl; cout "Note
参见英文答案 >
Checking for an empty file in C++ ????????????????????????????????????8个
我正在尝试使用eof和peek,但两者似乎都没有给我正确的答案. if (inputFile.fail()) //check for file open failure { cout << "Error opening file" << endl; cout << "Note that the program will halt" << endl;//error prompt } else if (inputFile.eof()) { cout << "File is empty" << endl; cout << "Note that program will halt" << endl; // error prompt } else { //run the file } 它使用此方法无法检测到任何空文件.如果我使用inputFile.peek而不是eof,它会将我的好文件作为空文件. 解决方法
请使用以下方式查看
if ( inputFile.peek() == std::ifstream::traits_type::eof() ) { // Empty File } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- (转载)flash图形遮挡ext组件的问题处理
- 技术周刊 Vol.10 - React Native丨Learn Once, Write Anywh
- 有没有办法禁用’iOS Team Provisioning Profile:*’自动创
- Cocos2d-x游戏开发——血量条
- cocos2d-iphone – cocos2d v2.0升级和RootViewController
- XML序列化和空值 – C#
- sqlite3 多线程问题...(转载)
- ruby-on-rails-3 – 使用资产前缀时,由于缺少清单文件,Capi
- 运行ROR应用程序时出现Sqlite-3错误
- SONObject jsonObject=JSONObject.fromObject(map) 执行到这