Namespaces
Variants

std::basic_stringbuf<CharT,Traits,Allocator>:: seekpos

From cppreference.net
protected :

virtual pos_type seekpos ( pos_type sp,

std:: ios_base :: openmode which = std:: ios_base :: in | std:: ios_base :: out ) ;

가능한 경우 std::basic_streambuf::gptr 및/또는 std::basic_streambuf::pptr sp 가 가리키는 위치로 재배치합니다.

seekoff ( off_type ( sp ) , std:: ios_base :: beg , which ) 를 효과적으로 실행합니다.

목차

매개변수

sp - 스트림 위치, 예를 들어 seekoff() 또는 seekpos() 로 얻은 값
which - 입력 시퀀스, 출력 시퀀스 또는 둘 다에 영향을 줄지 정의합니다. 다음 상수 중 하나 또는 조합일 수 있습니다:
상수 설명
in 입력 시퀀스에 영향
out 출력 시퀀스에 영향

반환값

sp 성공 시 또는 pos_type ( off_type ( - 1 ) ) 실패 시 반환됩니다.

참고 사항

seekpos() std::basic_streambuf::pubseekpos() 에 의해 호출되며, 이는 다시 std::basic_istream::seekg() std::basic_ostream::seekp() 의 단일 인자 버전에 의해 호출됩니다.

예제

#include <sstream>
#include <iostream>
struct mybuf : std::stringbuf
{
    mybuf(const std::string& str) : std::stringbuf(str) {}
    pos_type seekpos(pos_type sp, std::ios_base::openmode which)
    {
        std::cout << "Before seekpos(" << sp << "), size of the get area is "
                  << egptr() - eback() << " with "
                  << egptr() - gptr() << " read positions available.\n";
        pos_type rc = std::stringbuf::seekpos(sp, which);
        std::cout << "seekpos() returns " << rc << ".\nAfter the call, "
                  << "size of the get area is "
                  << egptr() - eback() << " with "
                  << egptr() - gptr() << " read positions available.\n";
        return rc;
    }
};
int main()
{
    mybuf buf("12345");
    std::iostream stream(&buf);
    stream.seekg(2);
}

출력:

Before seekpos(2), size of the get area is 5 with 5 read positions available.
seekpos() returns 2.
After the call, size of the get area is 5 with 3 read positions available.

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 375 C++98 std::ios_base 의 static 상수 멤버들이
std::basic_ios 의 멤버로 잘못 명시됨
수정됨
LWG 564 C++98 gptr 및/또는 pptr 을 어떻게 재위치해야 하는지 불명확했음 seekoff() 에 의해 재위치됨

참고 항목

seekpos 를 호출합니다
( std::basic_streambuf<CharT,Traits> 의 public 멤버 함수)
[virtual]
상대 주소 지정을 사용하여 입력 시퀀스, 출력 시퀀스 또는 둘 모두에서 다음 포인터의 위치를 재설정합니다
(가상 protected 멤버 함수)
[virtual]
절대 주소 지정을 사용하여 파일 위치를 재설정합니다
( std::basic_filebuf<CharT,Traits> 의 가상 protected 멤버 함수)
[virtual]
절대 주소 지정을 사용하여 입력 시퀀스, 출력 시퀀스 또는 둘 모두에서 다음 포인터의 위치를 재설정합니다
( std::strstreambuf 의 가상 protected 멤버 함수)