May 2017
Intermediate to advanced
590 pages
17h 18m
English
To serialize/deserialize POD types that do not contain pointers, use ofstream::write() and ifstream::read(), as shown in the previous recipe:
std::vector<foopod> output { {true, '1', {1, 2}}, {true, '2', {3, 4}}, {false, '3', {4, 5}} }; std::ofstream ofile("sample.bin", std::ios::binary); if(ofile.is_open()) { for(auto const & value : output) { ofile.write(reinterpret_cast<const char*>(&value), sizeof(value)); } ofile.close(); }
std::vector<foopod> input; std::ifstream ifile("sample.bin", std::ios::binary); if(ifile.is_open()) { while(true) { foopod value; ifile.read(reinterpret_cast<char*>(&value), ...Read now
Unlock full access