Please help!

This is a discussion on Please help! within the C++ Programming forums, part of the General Programming Boards category; Ok, I want to look through lines in a .txt file. I know how to search for a certain file. ...

  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

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