I am once more working to convert some older code from VC++ 6.0. I have run into a bug problem with ifstream. Below is a small sample project that I am trying to get to work as a "proof of concept" of sorts. It replicates my problem on a smaller scale. Here we go.
#include
"stdafx.h"#include
<iostream>using
namespace std;#include
<fstream>char
*filename = "PL_TABLE.DAT";int
_tmain(int argc, _TCHAR* argv[]){
char comments[150];
ifstream datafile;
datafile.open(filename);
if (!datafile.good())
cout << "File Bad!";
// Read header
//Class.ReadHeader(datafile);
int num_entries;
datafile.getline(comments,150,':') >> num_entries;
datafile.get();
datafile.getline(comments,150); // read second comment line
for (int i=0; i<num_entries; i++)
{
int index;
datafile.getline(comments,30);
datafile >> index;
if (index < 0 || index >=250)
cout << "Error!";
else
cout << "No Error!";
}
}
And here is the format of the "PL_TABLE.DAT". (The spacing is a bit off from what it looks like after I pasted it in here.)
There are more listings than just these two but they represent the setup.
number of players in file : 232
Name # T C D V R I T TC LC Z M B BC S A Tu Se D J WR L W H
AH-1W 2 1 5 739 5 6 4 3 15 2 2 0 14 0 15 6 8 24 3 1 10000 13.87 3.28 4.44
AV-8B 3 2 6 662 5 2 80 2 14 1 1 0 16 6 14 7 0 23 3 0 10000 15.58 9.25 3.55
Now, the specific problem lies in that the line, "datafile >> index;", is not reading in an index regardless of what I try to tweak. It should be reading, 2 on the first loop, 3 on the next, and so on and so forth. Now that this has been brought to VS 2005, it won't run properly. What am I missing Any advice or comments are welcome, thank you.