I’m trying to fill two arrays with an fstream. One is string and one is int. The string array (name) populates fine, but the char array only populates the first value.
void fillInventory(ifstream &fin, int costArray[],string itemArray[])
{
string name = "junk";
string cost;
int i = 0;
int max = 0;
stringstream convert;
while(name != "none")
{
getline(fin, name);
getline(fin, cost);
if(name != "none")
{
itemArray[i] = name;
convert<<cost;
convert >> costArray[i];
}
i++;
}
}
Am I using stringstream wrong or is my logic off, or something else altogether?
When you do this:
You’ve reached the EOF on the stringstream, which sets the
eofbitflag, causing future operations to fail. Reset the flags in order to continue: