C++ 如何从c+中的二进制文件中读取类+;
我有这个密码应该是C++ 如何从c+中的二进制文件中读取类+;,c++,file,binaryfiles,C++,File,Binaryfiles,我有这个密码应该是 从用户向类对象读取数据 将数据写入二进制文件 从二进制文件读取数据 向用户显示它 这是上课时间 class Bahd{ private: string name; long acc_no; long double bal; public: friend istream& operator >>(istream& src,Bahd& b);
class Bahd{
private:
string name;
long acc_no;
long double bal;
public:
friend istream& operator >>(istream& src,Bahd& b);
friend ostream& operator <<(ostream& dest,Bahd& b);
};
class Bahd{
私人:
字符串名;
长牙;
长双耳;
公众:
friend istream&operator>>(istream&src,Bahd&b);
朋友OsFrand和操作符不能识别序列化(即,假设你在内存中处理一些随机字节并移动这些字节)C++中任何非平凡类。并且你的类中有一个<代码> STD::String ,这使得它不平凡——因为<>代码:STD::String < /C>是不平凡的。
相反,您应该自行序列化它。…例如,使用
*** Error in `./a.out': munmap_chunk(): invalid pointer: 0x00007ffccbfbca50 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x71e75)[0x7fdf6d79ae75]
/usr/lib/libc.so.6(+0x777c6)[0x7fdf6d7a07c6]
./a.out[0x401280]
./a.out[0x401156]
/usr/lib/libc.so.6(__libc_start_main+0xf0)[0x7fdf6d749610]
./a.out[0x400e69]
======= Memory map: ========
**more lines here**
Aborted (core dumped)
class Bahd{
private:
string name;
long acc_no;
long double bal;
public:
friend istream& operator >>(istream& src,Bahd& b);
friend ostream& operator <<(ostream& dest,Bahd& b);
};