CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008

    help with reading a file

    I am working on reading the contents of a file that looks like this

    Larry 4 M 40
    Leslee 6 F 99
    Mary 9 F 39
    Hank 6 M 88
    Eden 7 F 71
    Drake 5 M 94
    Ava 4 F 28
    Seth 4 M 11
    Renaldo 3 M 77
    Carrie 8 F 68

    I have been able to read the data in and print it to the screen by doing this
    cout << fixed << showpoint << setprecision(2);
    	//getting the information for the file
    	cout << "Please enter the full path to the file: ";
    	getline(cin, inputFileName);
    	//Open the input file.
    	//check to see that the file was opened
    		cout << "Unable to opent the input file" << endl;
    	//set up a while loop to read to the end of the file
    	while(inputFile.peek() != EOF)
    		getline(inputFile, line);
    		cout << line << endl;
    my problem is that I am trying to get the data into variable so that I can work with it. I need to add up the scores and average them, So I have taken them in this way

    		inputFile >> firstName >> age >> gender >> score;
    		cout << firstName << age << gender << score << endl;
    that was my test code to see if it is working but it's not printing anything on the screen. I should mention that I am a beginner and I have only been working with this code for 3 days. So if you help, please explain in newbie terms

  2. #2
    Join Date
    Jan 2008

    Re: help with reading a file

    I think I figured it out. I needed to add



    before my next loop.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.