mercredi 28 octobre 2015

Issue reading variables from a file

I have a file with just one line

"P00321 A 9"

I need to bring each of these in as 3 individual variables, but it seems they aren't being read correctly with the code I have.

ifstream inFile;
int hours;
string accountnum;
char servicecode;

inFile >> accountnum >> servicecode >> hours;

If I cout these accountnum comes up blank, servicecode comes up as an underlined @ symbol, and hours is a long decimal number.
What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire