I need to make this program write to a file and read it. I have got the writing part down but when it tries to read and display the information i get wierd numbers can anyone tell me whats wrong?
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
int main()
{
int num;
int counter=0;
int enter;
ofstream outstream("digits2.dat");
if(outstream.fail())
{
cout<<"File Problem"<<endl;
exit(1);
}
for(counter=0; counter<5; counter++)
{
outstream<<1;
outstream<<2;
outstream<<3;
}
outstream.close();
ifstream instream("digits2.dat"); //opens files for reading
if (instream.fail() )
{
cout<<"File problem!"<<endl;
exit(1); //stop execution
}
while (instream>>num)
{
for(counter=0; counter<5; counter++)
{
cout<<num;
}
counter++;
outstream<<num;
cout<<num<<" ";
}
cout<<num<<endl;
cout<<"There were "<<counter<<" numbers read"<<endl;
instream.close();
cout<<"\n\n Program finished";
cin>>enter;
return(0);
}