Help reading data from text file properly.
This portion of my code i can't get to work.
The text file looks like this:
Vanilla 3
Chocolate 9
Chocolate 8
Vanilla 7
Chocolate 6
Lemon 5
It outputs the following and I'm not sure why:
0 Vanilla 3
0
0
0
0
0
1 2 3 4 5 6
|
while(i<size){
getline(in, *(flavor+i));
in >> *(weight+i);
cout<<*(weight + i)<< " "<<*(flavor + i)<<endl;
i++;
}
|
I see now that it's probably because there are blank lines. How could i fix that?
You might be able to just do this:
1 2 3
|
while (i < size && in >> flavor[i]) {
in >> weight[i++];
}
|
Topic archived. No new replies allowed.