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. File Read/Write buffer lenght

File Read/Write buffer lenght

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 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.
  • T Offline
    T Offline
    tanarnelinistit
    wrote on last edited by
    #1

    I have a file in which I write some names. lets say: Fiat, Ford, BMW. How can I open the file and read the entries one by one. eg: if only want to read Fiat and Ford then read only Fiat and Ford.

    N _ H 3 Replies Last reply
    0
    • T tanarnelinistit

      I have a file in which I write some names. lets say: Fiat, Ford, BMW. How can I open the file and read the entries one by one. eg: if only want to read Fiat and Ford then read only Fiat and Ford.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      if ur writing this name in seperate lines, u can use CStdioFile::ReadString()..

      nave

      T 1 Reply Last reply
      0
      • T tanarnelinistit

        I have a file in which I write some names. lets say: Fiat, Ford, BMW. How can I open the file and read the entries one by one. eg: if only want to read Fiat and Ford then read only Fiat and Ford.

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        How are you trying to open a FILE? Using FILE * - fread(),fgetc(),fscanf(). CFile::Read(). CStdioFile::ReadString()- these classes have methods to read from the file.

        Somethings seem HARD to do, until we know how to do them. ;-)_AnShUmAn_

        1 Reply Last reply
        0
        • N Naveen

          if ur writing this name in seperate lines, u can use CStdioFile::ReadString()..

          nave

          T Offline
          T Offline
          tanarnelinistit
          wrote on last edited by
          #4

          Thanks a lot it works using ReadString(). But how can I edit the file and replace Fiat with Mercedes, let's say?

          N D 2 Replies Last reply
          0
          • T tanarnelinistit

            I have a file in which I write some names. lets say: Fiat, Ford, BMW. How can I open the file and read the entries one by one. eg: if only want to read Fiat and Ford then read only Fiat and Ford.

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

            In additional you can use CFile m_file(m_Filename,CFile::modeRead); CArchive m(&m_file,CArchive::load); m.ReadString(str); ....

            _**


            **_

            WhiteSky


            1 Reply Last reply
            0
            • T tanarnelinistit

              Thanks a lot it works using ReadString(). But how can I edit the file and replace Fiat with Mercedes, let's say?

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #6

              tanarnelinistit wrote:

              how can I edit the file and replace Fiat with Mercedes

              this is a little bit difficult. here Mercedes have more characters than Fiat. U cannot insert character in a file in any place other that EOF. But replacing Fiat with a word of same character is possible. Move the file pointer to the begining of the word using CFile::Seek() function. then use CFile::Write() to replace it.

              nave

              1 Reply Last reply
              0
              • T tanarnelinistit

                Thanks a lot it works using ReadString(). But how can I edit the file and replace Fiat with Mercedes, let's say?

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

                Read each of the lines from the "old" file into the "new" file up to the line that needs to be changed. Write the line into the "new" file. Read the remaining lines from the "old" file into the "new" file. Close both files. Delete the "old" file. Rename the "new" file. Make sense?


                "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

                "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