I've serialised a map fine
std::map<std::string, std::string> userandPass;
saveData< std::map<std::string, std::string> >("userandPassBackup.txt", userandPass); // have removed &. why is this needed. i want to pass by reference
using the function
template <typename SaveClass>
void saveData(const std::string filename, SaveClass& c)
{
// File to be written to
boost::filesystem::remove(boost::filesystem::current_path() /
filename);
boost::filesystem::path myFile = boost::filesystem::current_path() /
filename;
// Declare an output file stream ofs that writes serialises to our
//backup file.
boost::filesystem::ofstream ofs(myFile.native());
// Declare archive ta that will use our output file stream
boost::archive::text_oarchive ta(ofs);
// Write to file
ta << c;
// How many records have been archived?
std::cout << c.size() << " records from have been successfully backed
up to " << myFile << "\n";
}
Deserialising (loading) however, fails, using:
loadData< std::map<std::string, std::string> >("userandPassBackup.txt", userandPass);
where the function is:
template <typename LoadClass>
void loadData(const std::string filename, LoadClass& c)
{
// File to be written to
boost::filesystem::remove(boost::filesystem::current_path() /
filename);
boost::filesystem::path myFile = boost::filesystem::current_path() /
filename;
// Declare an output file stream ofs that writes serialises to our
//backup file.
boost::filesystem::ifstream ifs(myFile.native());
// Declare archive ta that will use our output file stream
boost::archive::text_iarchive ta(ifs);
// Write to file
ta >> c;
// How many records have been archived?
std::cout << c.size() << " records from have been successfully backed
up to " << myFile << "\n";
}
My project compiles, but when I run it, I get the following error concerning the input stream:
libc++abi.dylib: terminating with uncaught exception of type boost::archive::archive_exception: input stream error Abort trap: 6
I don't see why this is happening. Would anyone be so kind as to point me in the right direction?
Thanks