Hi,
What I actually want to do is really quite simple,that is, convert all the data(of short type)in a file to their abstract values respectively.But I did not accomplish it. Here my code is listed:
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
char *in_name = "predicted_file.pre";
char *out_name = "abstracted_file.pre";
short i;
short i_abs;
ifstream in_file;
in_file.open(in_name,ios::binary);
ofstream out_file;
out_file.open(out_name,ios::binary | ios::app);
while (!in_file.eof())
{
in_file.read(reinterpret_cast<char*>(&i),sizeof(short));
if (in_file.eof())
break;
i_abs = abs(i);
out_file.write(reinterpret_cast<char*>(&i_abs),sizeof(short));
}
in_file.close();
out_file.close();
cout<<"Completed!"<<endl;
return 0;
}
The program can be compiled without error but it seemed to be trapped in a dead loop(a time too long for me to be tolerant,exactly) and the output file turned out to be very large in stead of being the same size as input file when I terminated the program by force. Anybody can tell me where I made mistakes and give me some clue for a effctive solution?Thank u in advance.I use VS 2005 if that makes any difference.
nanchuangyeyu