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. reading files

reading files

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 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.
  • R Offline
    R Offline
    RK_2000
    wrote on last edited by
    #1

    I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?

    J A N 3 Replies Last reply
    0
    • R RK_2000

      I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      If you are into iostreams, this is the way:

      std::istream in;
      std::string str;
      ...
      std::getline(in,str);

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      N 1 Reply Last reply
      0
      • R RK_2000

        I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?

        A Offline
        A Offline
        alex barylski
        wrote on last edited by
        #3

        CFile myFile("theFile.dat", options);

        int nSize = 663;

        char* buff = new char[nSize];

        myFile.Read(&buff, nSize);

        delete [] buff;

        I think this is what yer after... "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

        1 Reply Last reply
        0
        • R RK_2000

          I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Read into a CString. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

          A 1 Reply Last reply
          0
          • N Nish Nishant

            Read into a CString. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

            A Offline
            A Offline
            alex barylski
            wrote on last edited by
            #5

            Holy christ nice timing Nish! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

            J 1 Reply Last reply
            0
            • A alex barylski

              Holy christ nice timing Nish! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

              J Offline
              J Offline
              Joaquin M Lopez Munoz
              wrote on last edited by
              #6

              This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

              A N 2 Replies Last reply
              0
              • J Joaquin M Lopez Munoz

                This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                A Offline
                A Offline
                alex barylski
                wrote on last edited by
                #7

                Joaquín M López Muñoz wrote: This is unfair my answer gets listed the last, yet its associated time is prior than the others' !! ;P "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr

                1 Reply Last reply
                0
                • J Joaquin M Lopez Munoz

                  This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #8

                  Joaquín M López Muñoz wrote: my answer gets listed the last, yet its associated time is prior than the others' !! Thats cause you used STL in your answer. Chris M might not like that much. Nish :-D :-D Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

                  J 1 Reply Last reply
                  0
                  • N Nish Nishant

                    Joaquín M López Muñoz wrote: my answer gets listed the last, yet its associated time is prior than the others' !! Thats cause you used STL in your answer. Chris M might not like that much. Nish :-D :-D Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org

                    J Offline
                    J Offline
                    Joaquin M Lopez Munoz
                    wrote on last edited by
                    #9

                    LOL :laugh: Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                    1 Reply Last reply
                    0
                    • J Joaquin M Lopez Munoz

                      If you are into iostreams, this is the way:

                      std::istream in;
                      std::string str;
                      ...
                      std::getline(in,str);

                      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                      N Offline
                      N Offline
                      Navier
                      wrote on last edited by
                      #10

                      That's definitely the way I'd do it (you need an ifstream though not an istream) you get all the flexibility in the world and code re-use goes up 'cos you're not having to talk MFC. You can always use .c_str() on it if you need to get down and dirty. Why does anybody use anything else? I hear The Prisoner and 7of9 aren't getting along too well these days.

                      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