Reading and writing a std::vector into a file correctly
Try using an ostream_iterator/ostreambuf_iterator, istream_iterator/istreambuf_iterator, and the STL copy methods: #include <algorithm> #include <iostream> #include <iterator> #include <vector> #include <fstream> // looks like we need this too (edit by π) std::string path(“/some/path/here”); const int DIM = 6; int array[DIM] = {1,2,3,4,5,6}; std::vector<int> myVector(array, array + DIM); std::vector<int> newVector; std::ofstream FILE(path, std::ios::out | std::ofstream::binary); std::copy(myVector.begin(), myVector.end(), … Read more