The following code only prints the file once:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, const char *argv[])
{
ifstream infile;
infile.open("in", ios::binary);
char c;
while (infile.get(c))
{
cout << c;
}
infile.seekg(0, ios::beg);
infile.clear();
while (infile.get(c))
{
cout << c;
}
infile.close();
return 0;
}
I assume it has something to do with the eof flag after running through the file, but I don't know how to fix that.
Cheers.