getting data from a .txt file! HELF!
I'm doing this for a c++ class I have, and I'm stuck as to where to go next. This is super easy stuff I'm assuming, i'm just stuck.
The program is: I have to read this data:
Box | 250 5750
Sideline | 100 28000
Premium | 50 35750
General | 25 18750
This is data from seats sold to a game. the first number after the seat type is the price of the ticket, the second is the number sold. I am only telling you this so my code so far will make sense to you.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
string seatType;
double ticketPrice;
int ticketsSold;
double total;
double grandTotal=0.0;
inFile.open("c:\\tickets.txt");
outFile.open("c:\\Atchley_Alex.txt");
outFile<<fixed << showpoint;
outFile<< setprecision(2);
//gathering data from tickets.txt
getline(inFile, seatType, '|');
inFile >> ticketPrice >> ticketsSold;
//outputting data to Atchley_Alex.txt
outFile << setw(10) << seatType << setw(5) << ticketPrice
<< setw(5) << ticketsSold << endl;
//calculating total ticket sales
grandTotal = (ticketsSold+grandTotal);
system("pause");
inFile.close();
outFile.close();
return 0;
}
Now this might have not been TOTALLY neccissary to copy what I have so far. But! I do not know how to get to the second line of ticket-sales data. It reads the first one, the BOX string and the numbers after it just fine. HOWEVER, I don't know how to get it to go on a head and read the second one. I know i can set up a looping structure to make it repeat what it just did, but I don't know how to make it move on. Thanks for any help.
sorry if this has been covered in the FAQ, but I'm not sure what this would fall under.