CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    15

    How can I get the line number of a text file?

    I use CStdioFile::Open(...) to open a text file.
    I want to get the lines of this text file and I want to Read any line directly.How can I do that?
    Must I find all the "\r\n" in whole file?
    Thanks in advance.

    vector

  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: How can I get the line number of a text file?

    call the ReadString member function until it returns FALSE (which means EOF) and increment your line counter after every read operation:
    int i = 0;
    while( myFile.ReadString(myCString)) {
    i++;
    ...;
    }
    //i contains number of lines read.


  3. #3
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: How can I get the line number of a text file?

    In addition to what Lothar said, you could build an array of seek locations of
    every line by using GetPosition to tell you its starting point. With this you
    could position the file pointer (using Seek) at the start of any line you want
    and read it. But, you must first read every line once to be able to do this.






Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured