strange file opening problem
I am trying to use a file stream to count some data. The odd thing is the second time I use the ifstream, the file opens but it doesnt seem to read any data at all. Here is the code from the working portion:
Code:
ifstream infile;
ofstream outfile;
infile.open("08_28_06.txt");
while(getline(infile, line)){
string cat = line.substr(48, 3);
if(cat == "HHD" || cat == "TLT")
hhd++;
else if(cat == "BAK")
bak++;
else if(cat == "BEV")
bev++;
else if(cat == "BXB")
bxb++;
else if(cat == "CND")
cnd++;
else if(cat == "CNJ")
cnj++;
else if(cat == "CON")
con++;
else if(cat == "HAB" || cat == "MED")
haba++;
else if(cat == "RFR")
rfr++;
else if(cat == "SNK")
snk++;
else if(cat == "STA")
sta++;
else if(cat == "SNA")
sna++;
else
misc++;
}
infile.close();
And here is the non-working part:
Code:
line = "";
infile.open("NEW_BAK.csv");
bak = 0;
while(getline(infile, line)){
if(isdigit(line[0]))
bak++;
}
cout << "BAK: " << bak << endl;
infile.close();
I tried putting the statement: if(infile.is_open()) cout << "open"; before the loop and it works, so the file is opened... but it never enters the loop and there IS stuff in the file.
thanks