Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8494201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:14:05+00:00 2026-06-10T23:14:05+00:00

I have noticed this strange thing fstream obj(filename , ios::in); obj.seekp(7); is the same

  • 0

I have noticed this strange thing

fstream obj(filename , ios::in);
obj.seekp(7);

is the same as

fstream obj(filename , ios::in);
obj.seekg(7);

seekg and seekp do the same this and cause the same outcome, although i specified ios::in flag only

Why are they both work with fstream? And what is the difference between seekp and seekg with fstream?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:14:06+00:00Added an answer on June 10, 2026 at 11:14 pm

    basic_fstream is derived from basic_iostream which is derived from basic_istream and basic_ostream. So, basic_fstream has function seekp from basic_ostream and function seekg from basic_ifstream.

    In short, in your case, calls to seekp and seekg do same actions, since actions perfomed by basic_filebuf::seekpos depends only on open mode for basic_filebuf.

    basic_ostream<charT,traits>& seekp(pos_type pos);
    

    Effects: If fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::out). In case of failure,
    the function calls setstate(failbit) (which may throw ios_base::failure).

    Where pubseekpos calls seekpos (which is virtual, so, calls basic_filebuf::seekpos)

    pos_type seekpos(pos_type sp,
    ios_base::openmode which = ios_base::in | ios_base::out);
    

    Alters the file position, if possible, to correspond to the position stored in sp (as described below).
    Altering the file position performs as follows:

    1. if (om & ios_base::out) != 0, then update the output sequence and write any unshift sequence;

    2. set the file position to sp;

    3. if (om & ios_base::in) != 0, then update the input sequence;

    where om is the open mode passed to the last call to open(). The operation fails if is_open() returns
    false.

    Since you open file with ios_base::in function does 2 and 3 puncts.

    basic_istream<charT,traits>& seekg(pos_type pos);
    

    Effects: Behaves as an unformatted input function (as described in 27.7.2.3, paragraph 1), except that
    the function first clears eofbit, it does not count the number of characters extracted, and it does not
    affect the value returned by subsequent calls to gcount(). After constructing a sentry object, if fail()
    != true, executes rdbuf()->pubseekpos(pos, ios_base::in). In case of failure, the function calls
    setstate(failbit) (which may throw ios_base::failure).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noticed a strange thing today. I have some code like this in a project
I just noticed something strange. If I have this XML: <level number=7 background=background_5> and
I have noticed a strange thing that happens on my web app when the
I have noticed a strange thing happening in jQuery and wonder if anyone knows
I have noticed a number of kernel sources that look like this (found randomly
I'm new to jQuery and have noticed someone go: var $this = $(this); Why
This question may not directly relate to programming. I have noticed that the technology
I noticed that some stylesheets have something like this: body { font-size: 62.5%/1.2em; }
I have never come across this issue but most recently I noticed that a
I have a multithreaded application. However I noticed, I'm using OpenGL and this should

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.