so my input file is this
Target
Inventory:
tech 200 5
food 10 100
clothes 15 10
And i need to be able to record the store name, and its inventory
so far i have this working code
struct item {
std::string kind;
int price;
int quanity;
};
int main(int argc, char **argv){
std::fstream file;
file.open(argv[1]);
if (file.fail()){
std::cerr << "Error opening file!\n";
exit(1);
}
std::vector<struct item> inventory;
std::string name;
struct item target;
while(!file.eof()){
file >> name;
if(name == "Inventory:"){
while(file >> target.kind >> target.price >> target.quanity){
inventory.push_back(target);
}
break;
}
}
for(auto a : inventory){
std::cout << "Kind: " << a.kind << "\tPrice: " << a.price << "\tQuanity: " << a.quanity << std::endl;
}
so this code works fine, but apparently the text file is suppose to be like this
Target
Inventory:
tech,200,5
food,10,100
clothes,15,10
Now i cant seem to figure out how to get this working when each item is separated by a comma. Please help! Ive tried adding this line inside the second while loop but its no good
if (file.peek() == ','){
file.ignore();
}