首页 > 解决方案 > 建立数据库,读取方法

问题描述

谁能解释为什么这段代码不起作用?它说这个运算符不存在或类似的东西。请帮我

void Account::read_rec()
{
    std::ifstream infile;
    infile.open("record.bank", std::ios::binary);
    if (!infile)
    {
        std::cout << "[Error] File Not Found!" << std::endl;
        return;
    }

    std::cout << "\n***** Data from file *****" << std::endl;

    while (!infile.eof())
    {
        if (infile.read(reinterpret_cast<char*>(this), sizeof(*this) > 0))
        {
            show_data();
        }
    }
    infile.close();
}

标签: c++

解决方案


if (infile.read(reinterpret_cast<char*>(this), sizeof(*this) > 0))
//                                                          ^   ^
//                                                          A   B

函数调用的结束read应该在 A,而不是 B。

你把支架放错地方了。

没有read(char*, bool)功能;)


推荐阅读