Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem in reading a text file

Problem in reading a text file

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    learningvisualc
    wrote on last edited by
    #1

    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

    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

    CPalliniC M 2 Replies Last reply
    0
    • L learningvisualc

      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

      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

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I think your application is slow because of the huge number of items in the list control. You may consider using a virtual list, see, for instance, the following CodeProject article: Using virtual lists. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • L learningvisualc

        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

        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

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        Read the file THEN populate the list. and as my colleague wrote, use a virtual list.

        Watched code never compiles.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups