Read file bottom up

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Samant.Trupti@gmail.com

    Read file bottom up

    I need to read a huge file. The content that I want to read are
    somewhere at the bottom. Can anyone please let me know a way to read
    the file bottom up?
    Thanks
    Trupti
  • Jeff Schwab

    #2
    Re: Read file bottom up

    Samant.Trupti@g mail.com wrote:
    I need to read a huge file. The content that I want to read are
    somewhere at the bottom. Can anyone please let me know a way to read
    the file bottom up?
    Take a look at the istream::seekg method. It will let you position the
    file-pointer at an arbitrary place in the input stream.

    Comment

    • sean_in_raleigh@yahoo.com

      #3
      Re: Read file bottom up

      On Feb 18, 9:29 am, "Samant.Tru...@ gmail.com"
      <Samant.Tru...@ gmail.comwrote:
      I need to read a huge file. The content that I want to read are
      somewhere at the bottom. Can anyone please let me know a way to read
      the file bottom up?
      Thanks
      Trupti
      $ tail my_huge_file.tx t

      If that's not suitable for your environment, you
      should provide some details on that.

      Sean

      Comment

      • peter koch

        #4
        Re: Read file bottom up

        On 18 Feb., 17:42, Jeff Schwab <j...@schwabcen ter.comwrote:
        Samant.Tru...@g mail.com wrote:
        I need to read a huge file.  The content that I want to read are
        somewhere at the bottom.  Can anyone please let me know a way to read
        the file bottom up?
        >
        Take a look at the istream::seekg method.  It will let you position the
        file-pointer at an arbitrary place in the input stream.
        No it will not. seek will only (portably) position you somewhere where
        you have been before.

        /Peter

        Comment

        • peter koch

          #5
          Re: Read file bottom up

          On 18 Feb., 18:00, sean_in_rale... @yahoo.com wrote:
          On Feb 18, 9:29 am, "Samant.Tru...@ gmail.com"
          >
          <Samant.Tru...@ gmail.comwrote:
          I need to read a huge file.  The content that I want to read are
          somewhere at the bottom.  Can anyone please let me know a way to read
          the file bottom up?
          Thanks
          Trupti
          >
           $ tail my_huge_file.tx t
          >
          If that's not suitable for your environment, you
          should provide some details on that.
          >
          Sean
          tail is not appropriate as it is not portable, not C++ and not generic
          (tail is for text-files only).

          /Peter

          Comment

          • Jeff Schwab

            #6
            Re: Read file bottom up

            peter koch wrote:
            On 18 Feb., 17:42, Jeff Schwab <j...@schwabcen ter.comwrote:
            >Samant.Tru...@ gmail.com wrote:
            >>I need to read a huge file. The content that I want to read are
            >>somewhere at the bottom. Can anyone please let me know a way to read
            >>the file bottom up?
            >Take a look at the istream::seekg method. It will let you position the
            >file-pointer at an arbitrary place in the input stream.
            >
            No it will not. seek will only (portably) position you somewhere where
            you have been before.
            According to what? I'm looking at the draft standard for 0x, and don't
            see anything like that. The seekg method can fail, but I don't see
            anything magical about "where you have been before."

            Comment

            • guinness.tony@gmail.com

              #7
              Re: Read file bottom up

              On 22 Feb, 10:02, guinness.t...@g mail.com wrote:
              >
                  std::ifstream file( "myfile.dat ", std::ios_base:: binary );
              >
                  file.seekg( 0, std::ios_base:: end );
                  std::streampos const endpos = file.tellg();
                  file.seekg( 0, std::ios_base:: beg );
                  std::streamoff const file_length = file.tellg() - endpos;
              // Aaagh!
              std::streamoff const file_length = endpos - file.tellg();

              --
              Tony

              Comment

              • guinness.tony@gmail.com

                #8
                Re: Read file bottom up

                On 22 Feb, 15:59, James Kanze <james.ka...@gm ail.comwrote:
                Table 88 in 27.4.3.2 indicates that a distance (streamoff) can
                be obtained by subtracting one streampos from another.
                Although I can't find it explicitly stated, usage (and one of
                the footnotes) imply to me that streamoff is integral.
                >
                Which footnote?
                I think I must have been referring to footnote 174)
                (in 17.4.4.7): "... types described as synonyms for
                basic integral types, such as ... streamoff."

                --
                Tony

                Comment

                Working...