无法读取加载ifstream的文件 [英] Failing to read file loaded with ifstream

查看:637
本文介绍了无法读取加载ifstream的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

void bot_manager_item::create_games()
{
    games.clear();
    std::ifstream paths_in("C:\\Users\\bill hank\\Documents\\bot_plugins\\directory_listing.txt", std::ios::in);
    while (paths_in.good())
    {
        send_message("The path was good.");
        char q[5000];
        paths_in.getline(q, 5000);
        send_message(q);
        games.push_back(qanda(q));
    }
    paths_in.close();
}

我加载的文件存在,还有什么可能是错误? paths_in.good保持失败。

The file I'm loading exists, what else might be wrong? paths_in.good keeps failing.

编辑:我想出来了。我很生气的答案这个。基本上Windows允许您说明是否要显示文件扩展名。此窗口安装设置为说明不应显示扩展名。所以当我检查该文件一次又一次,我看到:directory.txt,并认为这意味着一切都很好的目录,而实际上文件名是directory.txt.txt

I figured it out. Wow am I annoyed by the answer to this. Basically Windows lets you say whether you want to show file extensions or not. This windows installation is set to say that the extension shouldn't be shown. So when I'm checking the file again and again I'm seeing: directory.txt and thinking that this means that everything is fine with the directory when in reality the filename was directory.txt.txt

推荐答案

如果 paths_in.good()保持失败,那么它意味着一些流错误标志被设置( badbit eofbit failbit )。

If paths_in.good() keeps failing then it means that some of the stream error flags are set (badbit, eofbit or failbit).


  • eofbit - 已达到文件结尾

  • badbit - 流缓冲区出错,如内存不足或流缓冲区内的异常。

  • failbit - 达到eof之外的其他一些错误

  • eofbit - end of file was reached
  • badbit - error with the stream buffer such as memory shortage or an exception inside the stream buffer is cast
  • failbit - some other error beside eof was reached

为了了解发生了什么,检查哪个错误位被设置首先,然后找出更多关于具体错误,以及什么可以导致它。

In order to find out what happened, you need to check which errorbit is set first, and then find out more about the specific error, and what can cause it.

这篇关于无法读取加载ifstream的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆