This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

### 136. seekp, seekg setting wrong streams?

Section: 29.7.4.4 [istream.unformatted] Status: CD1 Submitter: Howard Hinnant Opened: 1999-03-06 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [istream.unformatted].

View all issues with CD1 status.

Discussion:

I may be misunderstanding the intent, but should not seekg set only the input stream and seekp set only the output stream? The description seems to say that each should set both input and output streams. If that's really the intent, I withdraw this proposal.

Proposed resolution:

In section 27.6.1.3 change:

    basic_istream<charT,traits>& seekg(pos_type pos);
    Effects: If fail() != true, executes rdbuf()->pubseekpos(pos).

To:

    basic_istream<charT,traits>& seekg(pos_type pos);
    Effects: If fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::in).

In section 27.6.1.3 change:

    basic_istream<charT,traits>& seekg(off_type& off, ios_base::seekdir dir);
    Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir).

To:

    basic_istream<charT,traits>& seekg(off_type& off, ios_base::seekdir dir);
    Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::in).

In section 27.6.2.4, paragraph 2 change:

    -2- Effects: If fail() != true, executes rdbuf()->pubseekpos(pos).

To:

    -2- Effects: If fail() != true, executes rdbuf()->pubseekpos(pos, ios_base::out).

In section 27.6.2.4, paragraph 4 change:

    -4- Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir).

To:

    -4- Effects: If fail() != true, executes rdbuf()->pubseekoff(off, dir, ios_base::out).

[Dublin: Dietmar Kühl thinks this is probably correct, but would like the opinion of more iostream experts before taking action.]

[Tokyo: Reviewed by the LWG. PJP noted that although his docs are incorrect, his implementation already implements the Proposed Resolution.]

[Post-Tokyo: Matt Austern comments:
Is it a problem with basic_istream and basic_ostream, or is it a problem with basic_stringbuf? We could resolve the issue either by changing basic_istream and basic_ostream, or by changing basic_stringbuf. I prefer the latter change (or maybe both changes): I don't see any reason for the standard to require that std::stringbuf s(std::string("foo"), std::ios_base::in); s.pubseekoff(0, std::ios_base::beg); must fail.
This requirement is a bit weird. There's no similar requirement for basic_streambuf<>::seekpos, or for basic_filebuf<>::seekoff or basic_filebuf<>::seekpos.]