std::basic_stringbuf<CharT,Traits,Allocator>:: basic_stringbuf
| (1) | ||
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
=
std:: ios_base :: in | std:: ios_base :: out ) ; |
(C++11 이전) | |
|
explicit
basic_stringbuf
(
std::
ios_base
::
openmode
which
)
;
|
(C++11 이후) | |
|
basic_stringbuf
(
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out ) { } |
(2) | (C++11부터) |
|
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(3) | |
|
explicit
basic_stringbuf
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s,
std::
ios_base
::
openmode
which
=
|
(4) | (C++20 이후) |
|
basic_stringbuf
(
std::
ios_base
::
openmode
which,
const
Allocator
&
a
)
;
|
(5) | (C++20 이후) |
|
explicit
basic_stringbuf
(
const
Allocator
&
a
)
: basic_stringbuf ( std:: ios_base :: in | std:: ios_base :: out , a ) { } |
(6) | (C++20부터) |
|
template
<
class
SAlloc
>
explicit
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(7) | (C++20 이후) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(8) | (C++20 이후) |
|
template
<
class
SAlloc
>
basic_stringbuf
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
s,
|
(9) | (C++20부터) |
|
template
<
class
StringViewLike
>
explicit
basic_stringbuf
(
const
StringViewLike
&
t,
|
(10) | (C++26부터) |
|
template
<
class
StringViewLike
>
basic_stringbuf
(
const
StringViewLike
&
t,
|
(11) | (C++26부터) |
|
template
<
class
StringViewLike
>
basic_stringbuf ( const StringViewLike & t, const Allocator & a ) ; |
(12) | (C++26 이후) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs
)
;
|
(13) | (C++11 이후) |
|
basic_stringbuf
(
basic_stringbuf
&&
rhs,
const
Allocator
&
a
)
;
|
(14) | (C++20 이후) |
|
basic_stringbuf
(
const
basic_stringbuf
&
rhs
)
=
delete
;
|
(15) | (C++11 이후) |
std::basic_streambuf
베이스와
설명 전용 데이터 멤버
buf
및
mode
는 다음과 같이 초기화됩니다.
이러한 하위 객체들을 초기화한 후, 오버로드
(3-12)
는 마치
init_buf_ptrs
()
를 호출하는 것처럼 입력 및 출력 시퀀스를 초기화합니다.
| 오버로드 | std::basic_streambuf 베이스 |
buf
|
mode
|
|---|---|---|---|
| (1) | 기본 초기화됨 |
구현 정의
(아래 참조) |
which |
| (2) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (3) | s | which | |
| (4) | std :: move ( s ) | ||
| (5) | a | ||
| (6) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (7) | s | which | |
| (8) | { s, a } | ||
| (9) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (10) | { sv, Allocator ( ) } | which | |
| (11) | { sv, a } | ||
| (12) |
std::
ios_base
::
in
|
std:: ios_base :: out |
||
| (13) |
rhs
(복사 생성됨) |
std :: move ( rhs ) . str ( ) | rhs. mode |
| (14) | { std :: move ( rhs ) . str ( ) , a } |
std:: basic_string_view < CharT, Traits >> 일 때에만 오버로드 해결에 참여합니다.
- 다음에서 rhs_p 는 이 생성 직전의 rhs 상태를 가리키며, 다음 표현식들은 true 로 평가될 것입니다:
-
- str ( ) == rhs_p. str ( )
- getloc ( ) == rhs_p. getloc ( )
- gptr ( ) - eback ( ) == rhs_p. gptr ( ) - rhs_p. eback ( )
- egptr ( ) - eback ( ) == rhs_p. egptr ( ) - rhs_p. eback ( )
- pptr ( ) - pbase ( ) == rhs_p. pptr ( ) - rhs_p. pbase ( )
- epptr ( ) - pbase ( ) == rhs_p. epptr ( ) - rhs_p. pbase ( )
- 다음을 가정하자: rhs_a 는 이 생성 직후의 rhs 상태를 나타낸다. 그러면 다음 표현식들은 true 로 평가될 것이다:
-
- ! eback ( ) || eback ( ) ! = rhs_a. eback ( )
- ! gptr ( ) || gptr ( ) ! = rhs_a. gptr ( )
- ! egptr ( ) || egptr ( ) ! = rhs_a. egptr ( )
- ! pbase ( ) || pbase ( ) ! = rhs_a. pbase ( )
- ! pptr ( ) || pptr ( ) ! = rhs_a. pptr ( )
- ! epptr ( ) || epptr ( ) ! = rhs_a. epptr ( )
` 태그나 `
` 태그로 명시적으로 둘러싸이지는 않았지만, `mw-geshi cpp source-cpp` 클래스를 통해 코드임을 나타내고 있습니다. 지침에 따라 C++ 관련 용어(eback, gptr, egptr, pbase, pptr, epptr, rhs_a 등)와 코드 구조는 그대로 유지했습니다. 번역할 일반 텍스트가 포함되어 있지 않으므로, HTML 구조와 C++ 코드는 원본 그대로 보존되었습니다.
목차 |
매개변수
| s | - | 버퍼를 초기화하는 데 사용되는 std::basic_string | ||||||||||||||||
| t | - | 버퍼를 초기화하는 데 사용되는 ( std::basic_string_view 로 변환 가능한) 객체 | ||||||||||||||||
| a | - | 내부 std::basic_string 을 구성하는 데 사용되는 다른 할당자 | ||||||||||||||||
| rhs | - |
다른
basic_stringbuf
|
||||||||||||||||
| which | - |
스트림 열기 모드를 지정합니다. 비트마스크 타입이며 다음 상수들이 정의됩니다:
|
참고 사항
일반적으로 std::basic_stringstream 의 생성자에 의해 호출됩니다.
std::ios_base::in 및 std::ios_base::out 이외의 열기 모드에 대한 지원 수준은 구현체마다 다릅니다. C++11은 str() 및 이 생성자에서 std::ios_base::ate 에 대한 지원을 명시적으로 지정하지만, std::ios_base::app , std::ios_base::trunc , 그리고 std::ios_base::binary 는 구현체마다 다른 효과를 가집니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | 문자열 스트림과 std::string_view 연동 |
예제
std::basic_stringbuf
의 생성자를 직접 호출하는 방법을 보여줍니다:
#include <iostream> #include <sstream> int main() { // 기본 생성자 (mode = in | out) std::stringbuf buf1; buf1.sputc('1'); std::cout << &buf1 << '\n'; // 문자열 생성자 (at-end 모드, C++11) std::stringbuf buf2("test", std::ios_base::in | std::ios_base::out | std::ios_base::ate); buf2.sputc('1'); std::cout << &buf2 << '\n'; // append 모드 테스트 (컴파일러별 결과가 다름) std::stringbuf buf3("test", std::ios_base::in | std::ios_base::out | std::ios_base::app); buf3.sputc('1'); buf3.pubseekpos(1); buf3.sputc('2'); std::cout << &buf3 << '\n'; }
출력:
1 test1 est12 (Sun Studio) 2st1 (GCC)
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 432 | C++98 |
1. 오버로드
(1)
이 배열 객체를 할당하지 않음
2. 오버로드 (3) 이 입력 및 출력 시퀀스 초기화 방법을 명시하지 않음 |
1. 제한 사항 제거
2. 명시적으로 지정 |
| LWG 562 | C++98 |
오버로드
(3)
이
epptr()
을 마지막 기본 문자 다음 위치를 가리키도록 설정함
(if bool ( which & std:: ios_base :: out ) == true 인 경우) |
epptr() 을 해당 위치를 넘어서 설정할 수 있음 |
| P0935R0 | C++11 | 기본 생성자가 explicit였음 | implicit로 변경 |
참고 항목
|
문자열 스트림을 생성함
(
std::basic_stringstream<CharT,Traits,Allocator>
의 public 멤버 함수)
|