Ifstream and getline, help.
Hey,
getline seems to be reading the same line over and over again and only getting one word.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
ifstream file("file.dat");
if (file) {
getline(file, name);
file >> count;
//Variables
string name;
int numA= 0, numB= 0, numC= 0, numD= 0;
for (int y = 0; y < count; y++) {
getline(file, name);
file >> name >> numA >> numB >> numC;
Shop item(name, numA , numB , numC);
arrayShop[y] = item;
}
file.close();
|
Example of output file:
1 2 3 4 5 6 7 8
|
Name
3
item
0 0 0
itemtwo
0 0 0
itemtrhee
0 0 0
|
What happens when it loads into the array:
1 2 3
|
item 0 0 0
item 0 0 0
item 0 0 0
|
Anyone got any ideas?
Thanks.
Last edited on
Topic archived. No new replies allowed.