C++ C++;引发异常:读取访问冲突(fopen/fread struct)

C++ C++;引发异常:读取访问冲突(fopen/fread struct),c++,struct,fopen,fread,C++,Struct,Fopen,Fread,以下是我的结构: struct Account { string accID; string name; float balance; string currency; int status; }; 功能: Account layFileTaiKhoan(string id) { FILE * openfile; Account getAcc; string mypath = "Account\\" + id + ".dat"; openfile = fopen(mypath.c_str()

以下是我的结构:

struct Account {
string accID;
string name;
float balance;
string currency;
int status; 
};
功能:

Account layFileTaiKhoan(string id) {
FILE * openfile;
Account getAcc;
string mypath = "Account\\" + id + ".dat";
openfile = fopen(mypath.c_str(), "r");

fread(&getAcc, sizeof TaiKhoan, 1, openfile);

fclose(openfile);

return getAcc;
}
但我在使用我的函数获取保存在.dat文件中的结构时遇到了这个错误:“抛出异常:读取访问冲突”


请帮我解决这个错误,非常感谢您的帮助

您不能
fread
a
std::string
(或包含
std::string
的对象),因为
std::string
对象仅包含指向实际字符串的指针(某些库实现的短字符串除外)读取以前编写的指针是没有意义的,使用指针是未定义的行为。

什么是
TaiKhoan
?C和C++是不同的语言。选择您编译为的问题,并相应地编辑问题(包括标记)@PeteBecker:我不知道C有一个类型
string
,并且支持字符串文本上的加法运算符。