c++ - 建立数据库,读取方法
问题描述
谁能解释为什么这段代码不起作用?它说这个运算符不存在或类似的东西。请帮我
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();
}
解决方案
if (infile.read(reinterpret_cast<char*>(this), sizeof(*this) > 0))
// ^ ^
// A B
函数调用的结束read
应该在 A,而不是 B。
你把支架放错地方了。
没有read(char*, bool)
功能;)
推荐阅读
- javascript - 如何在 onclick 执行后重置旋转并使其可以称为增益
- angular - 如何根据从父表单的下拉列表中选择的值呈现嵌套的反应式表单?
- javascript - 更改表单(输入)值而不显示用户
- node.js - 即使文档有几个字段,也没有获取 firestore 文档字段数据
- typescript - 接口的奇怪行为
- java - 如何在 HashMap 中找到作为值的对象的字段?
- vim - 是双
在 VS Code 中不可映射? - ruby - 为什么一个明显的条件没有满足?
- java - 错误代码:1822。添加外键约束失败。引用表“地址”中的约束“employee_ibfk_1”缺少索引
- angular - 以 NgForm 作为参数的 typescript 方法的 Karma 单元测试