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

    Read 1000 Lines from text file in a single shot ........

    Hi,
    Below is the line of code(C++) for Reading the Textfile line by line.
    CString = strFilePath; // text path file path
    ifstream Textfile;
    Textfile.open(strFilePath,ios::in);
    std::string value;
    while(!Textfile.eof())
    {
    getline(Textfile,value); // Read line by line... takes too much time as the file size is bigger..

    }

    Textfile.close();

    Now the question is I am having 40MB text file size. I need to read 1000 Lines in a single shot (And upto read 1000 times to reach the whole 40 MB size) not line by line. How to do this?

    (ie) from 1 to 1000 line then 1001 to 2000 lines... upto max line count...
    reg,
    Subbu

  2. #2
    Join Date
    Jul 2009
    Posts
    3

    Re: Read 1000 Lines from text file in a single shot ........

    Im having a similar problem.. I want to read the string on line 6 of my textfile without having to read the 5 lines before it. is this possible or do i have to pad each string to 20 spaces (char[20]) and then search for charecter position 101 -120 (equivilant to line 6)?

    help would be appreciated!!

    I am making a Member Record and Edit Program using files.

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Read 1000 Lines from text file in a single shot ........

    Im having a similar problem.. I want to read the string on line 6 of my textfile without having to read the 5 lines before it. ... is this possible or do...
    No it's not possible - a line is determined by a '\r' followed by a '\n' character (in Windows).

    Therefore 5 lines can occupt 20 bytes or 200Mb depending on the line size and you have no way of knowing this without reading every character in the file looking for the above characters.

    As to subbuchen's question the same thing applies. However you can read large chunks of data from the file using the ifstream's read method.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

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