basic_ostream::seekp
Reset position in output stream.
basic_ostream<_Elem, _Tr>& seekp(
pos_type _Pos
);
basic_ostream<_Elem, _Tr>& seekp(
off_type _Off,
ios_base::seekdir _Way
);
매개 변수
_Pos
스트림 내의 위치입니다._Off
The offset relative to _Way._Way
One of the ios_base::seekdir enumerations.
반환 값
A reference to the basic_ostream object.
설명
If fail is false, the first member function calls newpos = rdbuf-> pubseekpos(_Pos), for some pos_type temporary object newpos. If fail is false, the second function calls newpos = rdbuf-> pubseekoff(_Off, _Way). In either case, if (off_type)newpos == (off_type)(-1) (the positioning operation fails), then the function calls istr.setstate(failbit). Both functions return *this.
예제
// basic_ostream_seekp.cpp
// compile with: /EHsc
#include <fstream>
#include <iostream>
int main()
{
using namespace std;
ofstream x("basic_ostream_seekp.txt");
streamoff i = x.tellp();
cout << i << endl;
x << "testing";
i = x.tellp();
cout << i << endl;
x.seekp(2); // Put char in third char position in file
x << " ";
x.seekp(2, ios::end); // Put char two after end of file
x << "z";
}
요구 사항
Header: <ostream>
네임스페이스: std