Error in reading file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Error in reading file

  1. #1
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Error in reading file

    Hi all,

    I have made a .txt file in a format that it contains data per line i.e. in the format

    /*text1*/
    /*text2abc*/

    And its not defined that how much data it can contain per line.

    I am reading this file in a per line format basis using this code

    Code:
    CStdioFile ptr;
    CString str;
    int i = 0;
    ptr.Open(file_name, CFile::ReadWrite, NULL);
    while(ptr.ReadString(str))
    {   
    m_List.InsertItem(i,str);
       i++;
    }
    ptr.Close();
    My problem is if a list contains more data(5000 lines or above) its taking a lot of time to read it.

    I also know that i can read particular number of bytes from buffer but the problem is how can i know that the line has been completely read or not.

    Can anybody please help me in this?
    Is there any other way to read thid file.

    Thanks in advance
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Error in reading file

    Is it taking long if the list contains too many elements, or if the file has too many lines?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Jan 2008
    Location
    India
    Posts
    780

    Re: Error in reading file

    supoose if the file is having 30,000 lines i will read a single line and then add it in list control and every time i read that file it is taking considerate amount of time to read and populate the list.
    IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Error in reading file

    30,000 lines in a list control? You didn't say "list control", you said only "list". It's a different thing. In this case the proper solution is a virtual list.
    http://msdn.microsoft.com/en-us/library/ye4z8x58.aspx
    http://www.codeguru.com/cpp/controls...icle.php/c4151

    You can find lots of other references too.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Error in reading file

    Quote Originally Posted by vjshankwar View Post
    supoose if the file is having 30,000 lines i will read a single line and then add it in list control and every time i read that file it is taking considerate amount of time to read and populate the list.
    reading 30000 lines from disk doesn't take that long, inserting them in a listcontrol does.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center