std::basic_stringbuf

std::basic_stringbuf (문자열 버퍼)

연관 문자 시퀀스가 메모리에 있는 임의 문자 시퀀스인 std::basic_streambuf예요. std::basic_string 인스턴스로 초기화되거나 그렇게 만들 수 있어요.

출처: cppreference

본문

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

template<
    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>
> class basic_stringbuf
    : public std::basic_streambuf<CharT, Traits>;

std::basic_stringbuf는 연관 문자 시퀀스가 메모리에 있는 임의 문자 시퀀스인 std::basic_streambuf예요. std::basic_string 인스턴스로 초기화되거나 그렇게 만들 수 있어요. 전형적인 구현은 std::basic_string 또는 이에 상응하는 크기 조정 가능한 시퀀스 컨테이너 객체를 데이터 멤버로 직접 보관하고, 이를 제어된 문자 시퀀스(여섯 포인터가 가리키는 배열)와 연관 문자 시퀀스(입력 연산의 문자 소스이자 출력의 대상)로 동시에 사용해요. 또한 전형적인 구현은 연관 스트림의 I/O 모드(입력 전용, 출력 전용, 입출력, 끝 위치 등)를 나타내는 std::ios_base::openmode 타입 데이터 멤버를 보관해요.

공통 문자 타입 typedef

  • std::stringbufstd::basic_stringbuf<char>
  • std::wstringbufstd::basic_stringbuf<wchar_t>

멤버 타입

  • char_type, traits_type, int_type, pos_type, off_type, allocator_type.

멤버 함수

  • (constructor) — stringbuf를 생성해요.
  • (destructor) — 파괴해요.
  • str — 문자열을 얻거나 설정해요.
  • view (C++20) — 문자 시퀀스 뷰를 얻어요.
  • underflow / pbackfail / overflow / seekoff / seekpos / setbuf — 버퍼 연산.

예제

#include <sstream>
#include <iostream>

int main()
{
    std::stringbuf buf;
    std::ostream os(&buf);
    os << "Hello, stringbuf!";
    std::cout << buf.str() << '\n'; // "Hello, stringbuf!"
}

더 알아보기 (Learn more)

cppreference