我正在创建一个C++控制台应用程序,用于保存矢量并将其加载到文件中。我正在保存和加载的文件有一个标题,它具有矢量的大小。C++未定义符号
这里是我的代码:
void loadFromFile()
{
ifstream iStream("file.ext", ios::binary);
fileHeader_t fHeader;
iStream.read((char*)&fHeader, sizeof(fileHeader_t));
if (fHeader.magicNumber = 0xDEADBEAF)
{
appointments.resize(fHeader.appointmentCount); iStream.read((char*)&appointments[0], fHeader.appointmentCount * sizeof(appointment));
}
}
void saveToFile()
{
ofstream oStream("file.ext", ios::binary);
fileHeader_t fHeader;
fHeader.magicNumber = 0xDEADBEAF;
fHeader.appointmentCount = appointments.size();
oStream.write((char*)&fHeader, sizeof(fileHeader_t));
oStream.write((char*)&appointments[0], sizeof(appointment) * appointments.size());
}
这里是头结构:
struct fileHeader_s
{
DWORD magicNumber;
size_t appointmentsCount;
}fileHeader_t;
我收到以下错误:
E2379 Statement missing ; E2451 Undefined symbol 'fHeader'
在下面几行:
fileHeader_t fHeader;
为什么会发生这种情况,更重要的是,我该如何解决这个问题?
感谢
更新
这里是我的全码:
class appointment
{
public:
appointment(string aDate, string aTime, string aType,
string aLocation, string aComments, bool aIsImportant,
string aReminderDate, string aReminderTime)
{
appDate = aDate;
appTime = aTime;
appType = aType;
appLocation = aLocation;
appComments = aComments;
appIsImportant = aIsImportant;
appReminderDate = aReminderDate;
appReminderTime = aReminderTime;
}
void setDate(string aDate)
{
appDate = aDate;
}
void setTime(string aTime)
{
appTime = aTime;
}
void setType(string aType)
{
appType = aType;
}
void setLocation(string aLocation)
{
appLocation = aLocation;
}
void setComments(string aComments)
{
appComments = aComments;
}
void setIsImportant(bool aIsImportant)
{
appIsImportant = aIsImportant;
}
void setReminderDate(string aReminderDate)
{
appReminderDate = aReminderDate;
}
void setReminderTime(string aReminderTime)
{
appReminderTime = aReminderTime;
}
string getDate()
{
return appDate;
}
string getTime()
{
return appTime;
}
string getType()
{
return appType;
}
string getLocation()
{
return appLocation;
}
string getComments()
{
return appComments;
}
bool getIsImportant()
{
return appIsImportant;
}
string getReminderDate()
{
return appReminderDate;
}
string getReminderTime()
{
return appReminderTime;
}
private:
appointment();
string appDate;
string appTime;
string appType;
string appLocation;
string appComments;
bool appIsImportant;
string appReminderDate;
string appReminderTime;
//person owner;
};
class calendar
{
public:
calendar()
{
loadFromFile();
}
~calendar()
{
saveToFile();
}
void createAppointment(string aDate, string aTime, string aType, string aLocation, string aComments, bool aIsImportant, string aReminderDate, string aReminderTime)
{
appointment newAppointment(aDate, aTime, aType, aLocation, aComments, aIsImportant, aReminderDate, aReminderTime);
appointments.push_back(newAppointment);
}
private:
vector<appointment> appointments;
string calCurrentDate;
string calCurrentTime;
void loadFromFile()
{
ifstream iStream("file.ext", ios::binary);
fileHeader_t fHeader;
iStream.read((char*)&fHeader, sizeof(fileHeader_t));
if (fHeader.magicNumber = 0xDEADBEAF)
{
appointments.resize(fHeader.appointmentCount); iStream.read((char*)&appointments[0], fHeader.appointmentCount * sizeof(appointment));
}
}
void saveToFile()
{
ofstream oStream("file.ext", ios::binary);
fileHeader_t fHeader;
fHeader.magicNumber = 0xDEADBEAF;
fHeader.appointmentCount = appointments.size();
oStream.write((char*)&fHeader, sizeof(fileHeader_t));
oStream.write((char*)&appointments[0], sizeof(appointment) * appointments.size());
}
typedef struct fileHeader_s
{
DWORD magicNumber;
size_t appointmentCount;
}fileHeader_t;
};
我得到以下2个错误:
[BCC32警告] Person.cpp(271 ):W8060可能不正确的赋值 完整的解析器上下文 Person.cpp (245):class calendar Person.cpp(290):决定实例化:void calendar :: loadFromFile() ---重置实例化解析器上下文... Person.cpp(267):解析:void calendar: :loadFromFile()
[BCC32错误]载体(608):E2247 '约会预约::()' 不可访问 全解析器上下文 矢量(607):决定实例:无效矢量> ::调整大小( (18):#include c:\ program files(x86)\ embarcadero \ rad studio \ 9.0 \ include \ dinkumware \ vector vector(8)unsigned int) ---重置解析器上下文以实例化... ):namespace std vector(330):class vector < _Ty,_Ax> vector(607):parsing:void vector> :: resize(unsigned int)
我可否请帮助解决此问题?
你忘了'struct'。 –
谢谢。我更新了我的问题。我可以请一些帮助吗? –
@DarrylJanecek:提示:问题是'private:appointment();'。 –