I am trying to make a small program which will write to a binary file,this is my code:
// program that writes to a binary file
#include <iostream>
#include <fstream>
using namespace std;
main() {
fstream* bfile = new fstream("file.bin", fstream::out | fstream::binary | fstream::ate);
int a = 2;
int var = 0;
bfile->write((char*)&a, sizeof(int));
bfile->read((char*)&var, sizeof(int));
cout << "Variable written to file contained" << var;
}
What i am trying to do is write to the binary file,and then check the files contents by printing out what is in the file,but i cant seem to grasp what i need to do in the next step,does anyone have any advice?
Thank you