[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/io/basic_ostream/seekp [Back]  [Original]

std::basic_ostream::seekp cppreference.com
cppreference.com

std::basic_ostream::seekp

cppreference.com

<metanoindex/>

<tbody> </tbody>
basic_ostream& seekp( pos_type pos );
(1)
basic_ostream& seekp( off_type off, std::ios_base::seekdir dir);
(2)
streambuf .
:
Sets the output position indicator of the current associated streambuf object.
Google.
. .
-, sentry , () ' . ( C++11) ,
:
First, constructs a sentry object which checks the stream for errors and flushes the tie()'d output streams. ( C++11) Afterwards,
Google.
. .

1)

( ) pos rdbuf()->pubseekoff(pos, std::ios_base::out). (pos_type)-1 , setstate(failbit).
:
sets the output position indicator to absolute (relative to the beginning of the file) value pos by calling rdbuf()->pubseekoff(pos, std::ios_base::out). If the call returns (pos_type)-1, executes setstate(failbit).
Google.
. .

2)

, off dir rdbuf()->pubseekoff(off, dir, std::ios_base::out). .
:
sets the output position indicator to offset off relative to dir by calling rdbuf()->pubseekoff(off, dir, std::ios_base::out). Does not report errors.
Google.
. .

pos
.
:
absolute position to set the output position indicator to.
Google.
. .
off
.
:
relative position to set the output position indicator to.
Google.
. .
dir
, . :
beg
end
cur
:
defines base position to apply the relative offset to. It can be one of the following constants:
beg
end
cur
Google.
. .

*this

1)

std::ios_base::failure , exceptions() & failbit != 0.
:
May throw std::ios_base::failure in case of failure, if exceptions() & failbit != 0.
Google.
. .

2)

, rdbuf()->pubseekoff()
:
Does not throw unless rdbuf()->pubseekoff() throws
Google.
. .

#include <sstream>
#include <iostream>

int main()
{
    std::ostringstream os("hello, world");
    os.seekp(7);
    os << 'W';
    os.seekp(0, std::ios_base::end);
    os << '!';
    os.seekp(0);
    os << 'H';
    std::cout << os.str() << '\n';
}

:

Hello, World!

.


(public -) []

(public - std::basic_istream) []

(public - std::basic_istream) []

Web Proxy Viewer  |  New URL  |  Original Page