Problems with fstream, one variabile for write and read

This is a discussion on Problems with fstream, one variabile for write and read within the C++ Programming forums, part of the General Programming Boards category; I use a fstream variabile to open a file in write and read mode. Code: fstream file; file.open("filepath", ios::in | ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    11

    Problems with fstream, one variabile for write and read

    I use a fstream variabile to open a file in write and read mode.

    Code:
    fstream file;
    file.open("filepath", ios::in | ios::out | ios:: binary);
    What's the difference between using seekg or seekp?
    There's really two different pointers or there's only one?

    Why if i read things, write things then move the pointer to the beginning to overwrite data (using for example file.seekp(0)) it writes the data to the end of the file?

    I used seekg and seekp either for moving read and write pointers (if there's really two), i also tried to use only seekg.. ah and everytime i write something, before reading or moving the pointer, i flush the fstream.
    Last edited by Smjert; 02-03-2009 at 08:54 AM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    seekg sets the position of the "get" pointer (where things will be read from); seekp sets the position of the "put" pointer (where things will be written to).

    You'll have to be a little more specific about what you tried to do and how it didn't work, I feel.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    11
    oh damn i hate myself a lot now xD
    So stupid mistake, i forgot that i close the handle to let another handle open the file and then when i reopen the old handle i use the append mode -.- .

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    >> There's really two different pointers or there's only one?
    Only one for files (or basic_filebuf to be specific).

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 07-24-2002, 06:33 AM
  2. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 02:49 PM
  3. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 09:52 AM
  4. I/O Problems - fstream
    By mol in forum C++ Programming
    Replies: 17
    Last Post: 10-16-2001, 03:50 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 02:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21