I am trying to create a drink machine simulator that reads from a text file called "DrinkMachineInventory.txt" for the input.
The text file must contain the following information:
Coca-Cola,0.75,20
Root Beer,0.75,20
Sprite,0.75,20
Spring Water,0.80,20
Apple Juice,0.95,20
I will not post the whole program, instead I will just post the part relevant to my issue. Can someone help getting this program to read from the txt file and display the information? Here is what I have so far but it is not displaying correct data after compiling.
in function initializeMachine you use getline once to read in the drink title, then you use the normal method to read in drinkprice. But the normal method reads until it encounters a whitespace, so it will read in "0.75,20" and etc. You'll need to use a different method.
39 - no matching function for call to `getline(std::ifstream&, double&, char)'
43 - no matching function for call to `getline(std::ifstream&, int&, char)'
weird, my guess is getline only reads in strings then. Another method you could use is to read the whole line into a string, then use a for loop to search through the string until a ',' is found and proceed to break off the current string into a separate string using substr();