I am in need of an explanation on how to pass information from my input file to my program. This is what I'm trying:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct BevInfo
{
char bevName[11];
float bevPrice;
int bevLeft;
};
int main(int argc, char *argv[])
{
BevInfo drink[5];
fstream myfile;
myfile.open("machine.txt", ios::in | ios::out);
myfile.getline(drink[0].bevName, 11);
myfile >> drink[0].bevPrice;
myfile >> drink[0].bevLeft;
myfile.close();
cout << drink[0].bevName << endl;
cout << drink[0].bevPrice << endl;
cout << drink[0].bevLeft << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
This is my input File:
Coca-Cola 0.75 20
Root Beer 0.75 20
Sprite 0.75 20
Spring Water 0.80 20
Apple Juice 0.95 20
Why is it not working?