I am using the below code to read and write to struct using the ifstream and ofstream classes. But for some reason I am not able to read back from the file.
#pragma pack(1)
struct test {
int m_id;
int m_size; //changed to integer
test(int id, int size) :m_id(id), m_size(size) {}
test() {};
};
#include <climits>
int main() {
ifstream in;
ofstream out;
out.open("binFile", ios::binary | ios::out);
in.open("binFile", ios::in | ios::binary);
test old(1, 7);
out.write(reinterpret_cast<char*>(&old), sizeof(old));
test new(10,100);
in.read(reinterpret_cast<char*>(&new), sizeof(new));
cout << new.m_size; //diplays 100
}