Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,305 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,052 people online right now. Registration is fast and FREE... Join Now!




Outputting data from a file

 
Reply to this topicStart new topic

Outputting data from a file

elispop122003
post 16 Feb, 2008 - 10:53 PM
Post #1


New D.I.C Head

*
Joined: 16 Feb, 2008
Posts: 2

I'm trying to write a program that will allow me to read 24 lines of data from a file at a time. After that has occurred, pause the output until user presses enter. Then continue to the rest of the data. For some reason when I run the code below I do not get any output at all. I figure that I need some sort of loop that will cause the program to stop every 24 lines. Please help!

CODE

#include<fstream>
#include<string>
#include<iostream>
using namespace std;

int main()
{
    ifstream dataFile;
    string buffer;
    char ch;
    char fileName[81];

    cout << "Please enter the name of the file: ";
    cin.getline(fileName, 81);

    dataFile.open(fileName, ios::in);
    cout << "Reading information from the file. \n\n";
    
    getline(dataFile, buffer);
    cout << buffer << endl;    
    
    cout << "Press Enter when ready to continue.";
    cin.get(ch);

    dataFile.close();
    cout << "\nDone. \n";

    return 0;
}
User is offlineProfile CardPM

Go to the top of the page

schnalf
post 17 Feb, 2008 - 05:22 AM
Post #2


D.I.C Head

**
Joined: 9 Feb, 2008
Posts: 124



Thanked 2 times
My Contributions


getline reads even only 1 line of the file. every time you read one line, the cursor jumps in the file in the next line, so that you can read the next line.

eof() returns 0 when the coursor is at the end of the file

CODE

while(!dataFile.eof())
{
    getline(dataFile, buffer);
        cout << buffer << endl;
}
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 02:08AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month