basic_istream::seekg

스트림에서 읽기 위치를 이동합니다.

basic_istream<Elem, Tr>& seekg(
    pos_type pos
);
basic_istream<Elem, Tr>& seekg(
    off_type off,
    ios_base::seekdir way
);

매개 변수

  • pos
    절대 위치 읽기 포인터를 이동 합니다.

  • off
    상대적으로 읽기 포인터를 이동 하는 오프셋 way.

  • way
    중 하나는 ios_base::seekdir 열거형입니다.

반환 값

스트림 (*이).

설명

첫 번째 멤버 함수는 절대 검색 수행, 두 번째 멤버 함수는 상대 검색을 수행 합니다.

[!참고]

두 번째 멤버 함수는 텍스트 파일을 사용 하지 마십시오, 표준 C++에서 지원 하지 않는 때문에 상대를 텍스트 파일에서 검색 합니다.

경우 실패 은 false 이며 첫 번째 멤버 함수 호출 newpos = rdbuf -> pubseekpos(pos), 일부 pos_type 임시 개체 newpos.경우 실패 은 false 이며 두 번째 함수 호출 newpos = rdbuf -> pubseekoff(off, way).두 경우 모두에서 경우 (off_type)newpos = (off_type)(-1) (배치 작업이 실패)를 함수 호출 istr.setstate(failbit).두 함수를 반환 합니다. *이.

경우 실패 멤버 함수를 수행할 아무 것도 마찬가지입니다.

예제

// basic_istream_seekg.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main ( ) 
{
   using namespace std;
   ifstream file;
   char c, c1;

   file.open( "basic_istream_seekg.txt" );
   file.seekg(2);   // seek to position 2
   file >> c;
   cout << c << endl;
}

입력: basic_istream_seekg.txt

0123456789

Output

2

요구 사항

헤더: <istream>

네임 스페이스: std

참고 항목

참조

basic_istream Class

iostream 프로그래밍

iostreams 규칙