Thread: getting data from a .txt file! HELF!

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    3

    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.
    Last edited by lastwaver0cker; 02-22-2006 at 02:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  5. spell check in C using a dictionary file
    By goron350 in forum C Programming
    Replies: 10
    Last Post: 11-25-2004, 06:44 PM