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. istream: seekg / tellg, peculiar behaviour

istream: seekg / tellg, peculiar behaviour

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
1 Posts 1 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
    LiquidEyes
    wrote on last edited by
    #1

    I'm having two istream-related problems. Please can somebody help... :confused: Problem 1

    void loadStuffFromStream (istream& stream)
    {
    	// goes too far!!
    	stream.seekg( length, ios_base::cur );
    }
    

    ***edited*** This seems to skip to an arbitrary position in the stream, instead of 'current position' + length bytes. Why does it do this? Problem 2

    char ch;
    int pos;
    ...
    pos = stream.tellg();		// now pos=0
    stream.get (ch);
    pos = stream.tellg();		// now pos=3585 ???
    stream.get (ch);
    pos = stream.tellg();		// now pos=3586
    stream.get (ch);
    pos = stream.tellg();		// now pos=3587
    stream.get (ch);
    // etc...
    

    Not so much a 'problem' as a matter of curiosity. Why is there a sudden leap in the read-position reported by tellg the first time I read from the stream? (N.B. It is reading the correct characters into ch!)

    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