Thread: Please help!

  1. #1
    BubbleMan
    Guest

    Question Please help!

    Ok, I want to look through lines in a .txt file. I know how to search for a certain file. How would I scan a single line until eof?

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279

    Lightbulb

    this reads in a line of code until the end of the line

    ifstream fin("c:\\yourFileGoesHere");
    string str;
    getline(fin, str, '\n');


    reads only a single line........

  3. #3
    ThunderCow
    Guest

    Cool

    i just wrote this up.. hope it helps

    #include <fstream.h>
    #include <iostream.h>

    void main()
    {
    char text1[5000];
    char filename[30];
    cout << "What file do you want to display?\n";
    cin.getline(filename, 30, '\n');
    ifstream file(filename);

    do
    {
    file.getline(text1, 5000, '\n');
    cout << text1;
    cout << "\n";
    }
    while (file.eof()!=1);

    file.close();
    }

Popular pages Recent additions subscribe to a feed