The following code is supposed to read in a line from a.txt file and identify two integers separated by a whitespace character. It doesn't seem to work however and I really don't understand why. Any help would be fantastic!
for (int i=0;i<10;i++)
{
out_file<<hex<<i+1000<<" "<<i+1000000<<endl;
}
out_file.close();
int CPU[2][10];
fstream input_file;
input_file.open("tracetest1.txt", ios::in);
if (!input_file.good())
{
cout << "FATAL ERROR: Could not open file 'trace.dat'";
system("PAUSE");
exit(1);
}
for (int i = 0; i < 10; i++)
{
input_file >> CPU[0][i];
input_file >> CPU[1][i];
cout<< hex<< CPU[0][i] << " " <<CPU[1][i]<< endl;
}
You're missing some hexes in your program. If your program doesn't know in advance that what it's reading in is a hexadecimal number, then how's it supposed to know that it's not garbage? :)