I have data stored in a deque that I wish to write to disk using fstream. So far this is the test code I have written.
int j = 10000;
deque<double> m_data;
for(int i = 0; i < j; i++)
{
m_data.push_back(i);
}
std::fstream myfile;
myfile.open ("data2.bin", std::ios::out | std::ios::app | std::ios::binary );
for(int i = 0; i < j; i++)
{
myfile.write((const char*) &m_data[i], sizeof(m_data));
}
myfile.close();
deque<double> m_data2[sizeof(m_data)];
ifstream myfileIN;
myfileIN.open("data2.bin", std::ios::in | std::ios::binary);
// get length of file:
myfileIN.seekg(0, std::ios::end);
int length = myfileIN.tellg();
myfileIN.seekg(0, std::ios::beg);
char* buffer = new char[length];
myfileIN.read(buffer, length);
This code does run and compile just fine, BUT I have no idea how to go from the string stored in buffer back into a deque container. So, help, please.
Also, am I writing (serializing) this data in the most efficient manner?
Thank you!!