std::fpos

std::fpos (스트림·파일 절대 위치)

스트림이나 파일에서 절대 위치를 식별하는 클래스 템플릿이에요. 각 fpos 객체는 스트림의 바이트 위치(보통 std::streamoff 타입의 private 멤버)와 현재 이동 상태(State 타입의 값, 보통 std::mbstate_t)를 보관해요.

출처: cppreference

본문

<ios> 헤더에 정의돼 있어요.

template< class State >
class fpos;

클래스 템플릿 std::fpos의 특수화는 스트림이나 파일의 절대 위치를 식별해요. 각 fpos 타입 객체는 스트림의 바이트 위치(보통 std::streamoff 타입의 private 멤버)와 현재 이동 상태(State 타입의 값, 보통 std::mbstate_t)를 보관해요. std::fpos<std::mbstate_t>에 대한 typedef 이름들이 제공돼요.

  • std::streamposstd::fpos<std::char_traits<char>::state_type>
  • std::wstreamposstd::fpos<std::char_traits<wchar_t>::state_type>
  • std::u8streampos, std::u16streampos, std::u32streampos — 각 문자 타입용.

멤버 함수

  • (constructor) — 위치를 생성해요(기본, streamoff에서, 다른 State에서).
  • operator streamoff — 바이트 위치를 반환해요.
  • state — 이동 상태를 얻거나 설정해요.
  • operator+=, operator-=, operator+, operator- — 위치 산술.
  • operator==, operator!= — 비교.

예제

#include <iostream>
#include <sstream>

int main()
{
    std::istringstream s("abc");
    std::streampos p = s.tellg(); // 현재 위치 얻기 (fpos)
    char c;
    s >> c;
    std::cout << (p == s.tellg()) << '\n'; // 위치를 이동한 뒤에는 false
}

더 알아보기 (Learn more)

cppreference