struct user
{
string name;
int age;
};
//save a structure object to a file
template<typename structure>
void SaveDataBase(string filename,structure &StructureVariable )
{
remove(filename.c_str());
ofstream writefile(filename.c_str(),std::ios::binary);
writefile << StructureVariable;//usrName is a user object
writefile.close();
}
//read a structure object from a file
template<typename structure>
void ReadDataBase(string filename,structure &StructureVariable )
{
ifstream readfile(filename.c_str(),std::ios::binary);
readfile >> StructureVariable;
readfile.close();
}
//using it:
user usrName;
user usrName2;
usrName.age=23;
usrName.name="joaquim miguel";
SaveDataBase("username1.dat",usrName);
ReadDataBase("username1.dat",usrName2);
mnuExitSys2.Caption=usrName2.name;//getting the name
on SaveDataBase(): writefile << StructureVariable;
i get an error:
"cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'"
what anyone can tell me?