Need hand with file input/Output

This is a discussion on Need hand with file input/Output within the C++ Programming forums, part of the General Programming Boards category; Howdy all, I am having a bit a trouble understanding how file input and output works. I am working on ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    33

    Need hand with file input/Output

    Howdy all,
    I am having a bit a trouble understanding how file input and output works. I am working on a Lab for Intro to C++ and I need to work with input output and loops:


    Process input from 2 files: salesDay.dat and salesNight.txt
    Must allow the user to type the name for the input file so that the name can be stored in a variable. This allows you to process either file with no changes to your program.
    Will input 4 salesman from the day crew and 4 from the night crew
    Will use a counter and accumulator
    Will compute and print the average sales.
    Will print 2 salesman if there is a tie. (Check the sample screen). We will assume that no more than 2 salesman will ever have the same sales figure but 2 might.
    Will store the salesman's ID (a number) and his sales figure for printing later.
    Will use at least one switch statement.
    Format all output as closely as possible to the sample screens.


    That's what I need to do. Now I have started writing the code but I am stuck at opening up the input files. This is what I have so far.


    Code:
    #include <string>
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    
    
    int main()
    
    {
    
    	string winner;
    	int salesmanId;
    	int salesmanNumber;
    	string winningMessage;
    	string filename;
    	ifstream inData;
    	ofstream outData;
    
    
    
    	
    
    
    	cout<<"Please enter the name of the data file: ";
    	getline(cin,filename);
    
    	inData.open("salesday.dat");
    	
    
        
    
    
        cout<<setw(25)<<"Salesman Contest"<<endl;
        cout<<endl;
    	cout<<setw(25)<<"October 2003"<<endl;
    	cout<<endl;
    	cout<<setw(15)<<"And the winner is: "<<endl;
    	cout<<endl;
    	cout<<"Amount of sales: "<<endl;
    	cout<<endl;
    
    
    
    }

    I don't want answers as I want to figure it out myself. But y question is is this correct for inputting a file? Does the input get stored in a variable? I am kinda looking for a pointer in the right direction. Again, I wanna figure this out but I'm a little cinfused with file input and output.


    P.S. The tutorial wasn't much help

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    33
    I am trying to understand the concept here......also where do I need to put the file in order for my program to read it?

  3. #3
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    indata >> dump;
    outdata << dump;

    note: dump should be a char string, char dump[];

    That is how you input.output, along with everything else you did. You'll also want:
    indata.close();
    outdata.close();

    getline(cin,filename); //whats this for?

    I can't quite understand what you are trying to do, but I hope the above was of help.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    33
    I'm not sure if I know what I'm trying to do either. Basically I want to read the input files and process the information. Basically what I need to know is how do I read and process information once I open a file?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 05:28 PM
  3. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21