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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to read a file line by line in VC++

How to read a file line by line in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
10 Posts 6 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.
  • V Offline
    V Offline
    vikram vit
    wrote on last edited by
    #1

    Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance. Regards, Vikram

    P J D H 4 Replies Last reply
    0
    • V vikram vit

      Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance. Regards, Vikram

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      Use istream::getline.

      Prasad Notifier using ATL | Operator new[],delete[][^]

      1 Reply Last reply
      0
      • V vikram vit

        Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance. Regards, Vikram

        J Offline
        J Offline
        jk chan
        wrote on last edited by
        #3

        You can try fgets which is C function look the sample code snippet FILE *fp = fopen("c:\\file.txt","r"); char ar[100]; while(fgets(ar,100,fp)) { print (ar); } fclose(fp);

        If u can Dream... U can do it

        1 Reply Last reply
        0
        • V vikram vit

          Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance. Regards, Vikram

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          And if you are using MFC, there's CStdioFile::ReadString().


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          S 1 Reply Last reply
          0
          • V vikram vit

            Can anyone please help me to find out a simple way to read a text file line by line in Visual C++ 6. Thanks in advance. Regards, Vikram

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Can you be more specific Its a minimum info


            WhiteSky


            V 1 Reply Last reply
            0
            • H Hamid Taebi

              Can you be more specific Its a minimum info


              WhiteSky


              V Offline
              V Offline
              vikram vit
              wrote on last edited by
              #6

              yeah WhiteSky..I am developing a dialog based MFC application, in which i want to read a text file line by line for parsing and identifying certain charaters such as (), *. % etc. So i wanted to read the text file line by line to count occurance of each keyword at each line. Hope this information is sufficient.

              H 1 Reply Last reply
              0
              • V vikram vit

                yeah WhiteSky..I am developing a dialog based MFC application, in which i want to read a text file line by line for parsing and identifying certain charaters such as (), *. % etc. So i wanted to read the text file line by line to count occurance of each keyword at each line. Hope this information is sufficient.

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #7

                well you can use of David answer CStdioFile::ReadString or CFile::Read :)


                WhiteSky


                V 1 Reply Last reply
                0
                • H Hamid Taebi

                  well you can use of David answer CStdioFile::ReadString or CFile::Read :)


                  WhiteSky


                  V Offline
                  V Offline
                  vikram vit
                  wrote on last edited by
                  #8

                  thanks very much...but i think CFile::Read reads the specified number of characters at one go. How do we know the size of each line well in advance. Is there any function in CFile that facilitates it?

                  D 1 Reply Last reply
                  0
                  • D David Crow

                    And if you are using MFC, there's CStdioFile::ReadString().


                    "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                    "Judge not by the eye but by the heart." - Native American Proverb

                    S Offline
                    S Offline
                    Sumesh V V
                    wrote on last edited by
                    #9

                    I think this will work CStdioFile::ReadString :)

                    1 Reply Last reply
                    0
                    • V vikram vit

                      thanks very much...but i think CFile::Read reads the specified number of characters at one go. How do we know the size of each line well in advance. Is there any function in CFile that facilitates it?

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      vikram.vit wrote:

                      How do we know the size of each line well in advance.

                      You don't (at least not without a lot of unnecessary code). That's why I suggested CStdioFile::ReadString() and not CFile::Read().


                      "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                      "Judge not by the eye but by the heart." - Native American Proverb

                      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