这就是我想说的。如何在其中写入和读取带有 std::vector 的二进制文件?
我在想类似的事情:
//============ WRITING A VECTOR INTO A FILE ================
const int DIM = 6;
int array[DIM] = {1,2,3,4,5,6};
std::vector<int> myVector(array, array + DIM);
ofstream FILE(Path, ios::out | ofstream::binary);
FILE.write(reinterpret_cast<const char *>(&myVector), sizeof(vector) * 6);
//===========================================================
但我不知道如何阅读这个向量。因为我认为以下是正确的,但事实并非如此:
ifstream FILE(Path, ios::in | ifstream::binary);
FILE.read(reinterpret_cast<const char *>(&myVector), sizeof(vector) * 6);
那么,如何进行操作呢?