Hey all,
I am a C++ newbie, and am working on some code. My code has several functions, one of which pulls data out of a file and puts it into some vectors I have set up.
The data in the file is in the following format:
int
string
int double double
int
string
int double double
.
.
.
It repeats that same progression several times.
Now ... everything works great, except that for some reason my code pulls out the last set of values twice.
So, if the string values in the file are Bob, James, and Stacy my string vector ends up with the following: [Bob, James, Stacy, Stacy].
I have no idea why the code would be pulling out the last items twice ... any ideas?
Its not a huge deal, I can just ignore the last position of the vector in all future code ... but I want to understand why its happening.
The code is below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
void input(ifstream& inp, vector<int>& itemID, vector<string>& itemName,
vector<int>& pOrdered, vector<int>& pInStore, vector<int>& pSold,
vector<double>& manufPrice, vector<double>& sellingPrice)
{
string item;
int id;
int order;
double manuf;
double selling;
while (inp)
{
inp >> id;
inp.ignore(256, '\n');
getline(inp, item);
inp >> order >> manuf >> selling;
itemID.push_back(id);
itemName.push_back(item);
pOrdered.push_back(order);
pInStore.push_back(order);
pSold.push_back(0);
manufPrice.push_back(manuf);
sellingPrice.push_back(selling);
}
}
|