std::basic_stringstream<CharT,Traits,Allocator>:: basic_stringstream
| (1) | ||
|
explicit
basic_stringstream
(
std::
ios_base
::
openmode
mode
=
std:: ios_base :: in | std:: ios_base :: out ) ; |
(C++11 이전) | |
|
explicit
basic_stringstream
(
std::
ios_base
::
openmode
mode
)
;
|
(C++11 이후) | |
|
basic_stringstream
(
)
: basic_stringstream ( std:: ios_base :: in | std:: ios_base :: out ) { } |
(2) | (C++11부터) |
|
explicit
basic_stringstream
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
str,
|
(3) | |
|
explicit
basic_stringstream
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
str,
|
(4) | (C++20 이후) |
|
basic_stringstream
(
std::
ios_base
::
openmode
mode,
const
Allocator
&
a
)
;
|
(5) | (C++20 이후) |
|
template
<
class
SAlloc
>
basic_stringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(6) | (C++20 이후) |
|
template
<
class
SAlloc
>
basic_stringstream
(
const
std::
basic_string
<
CharT, Traits, SAlloc
>
&
str,
|
(7) | (C++20 이후) |
|
template
<
class
SAlloc
>
explicit
basic_stringstream
|
(8) | (C++20 이후) |
|
template
<
class
StringViewLike
>
explicit
basic_stringstream
|
(9) | (C++26부터) |
|
template
<
class
StringViewLike
>
basic_stringstream
(
const
StringViewLike
&
t,
|
(10) | (C++26부터) |
|
template
<
class
StringViewLike
>
basic_stringstream ( const StringViewLike & t, const Allocator & a ) ; |
(11) | (C++26부터) |
|
basic_stringstream
(
basic_stringstream
&&
other
)
;
|
(12) | (C++11 이후) |
새로운 문자열 스트림을 생성합니다.
주어진
-
base_type을 std:: basic_iostream < CharT, Traits > 로, 그리고 -
buf_type을 std:: basic_stringbuf < CharT, Traits, Allocator > 로 정의합니다.
std::basic_iostream
베이스와
설명 전용 데이터 멤버
sb
는 다음과 같이 초기화됩니다.
|
오버로드
(Overload) |
std::basic_iostream 베이스 |
sb
|
|---|---|---|
| (1) | base_type ( std:: addressof ( sb ) ) [1] | buf_type ( mode ) |
| (2) | buf_type ( std:: ios_base :: in | std:: ios_base :: out ) | |
| (3) | buf_type ( str, mode ) | |
| (4) | buf_type ( std :: move ( str ) , mode ) | |
| (5) | buf_type ( mode, a ) | |
| (6) | buf_type ( str, mode, a ) | |
| (7) | buf_type ( str, std:: ios_base :: in | std:: ios_base :: out , a ) | |
| (8) | buf_type ( str, mode ) | |
| (9) | std:: addressof ( sb ) | { t, mode, Allocator ( ) } |
| (10) | { t, mode, a } | |
| (11) | { t, std:: ios_base :: in | std:: ios_base :: out , a } | |
| (12) |
other
의
std::basic_iostream
베이스로부터 이동 생성됨
|
other.sb
로부터 이동 생성됨
|
- ↑ std::basic_iostream 기본 클래스는 C++11 이전까지 base_type ( & sb ) 로 초기화되었습니다 (오버로드 (1,3) 의 경우).
목차 |
매개변수
| str | - | 문자열 스트림의 초기 내용으로 사용할 문자열 | ||||||||||||||||
| t | - | 문자열 스트림의 초기 내용으로 사용할 객체 ( std::basic_string_view 로 변환 가능) | ||||||||||||||||
| a | - | 문자열 스트림 내용 할당에 사용할 할당자 | ||||||||||||||||
| mode | - |
스트림 열기 모드를 지정합니다.
BitmaskType
으로, 다음 상수들이 정의됩니다:
|
||||||||||||||||
| other | - | 소스로 사용할 다른 문자열 스트림 |
참고 사항
문자열 변환과 같이 빈번한 루프에서 일회성
basic_stringstream
객체를 생성하는 것은 동일한 객체를 재사용하기 위해
str()
함수를 호출하는 것보다 훨씬 더 많은 비용이 발생할 수 있습니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | std::stringstream 과 std::string_view 연동, ( 9-11 ) |
예제
#include <iostream> #include <sstream> int main() { // 기본 생성자 (입력/출력 스트림) std::stringstream buf1; buf1 << 7; int n = 0; buf1 >> n; std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n'; // 입력 스트림 std::istringstream inbuf("-10"); inbuf >> n; std::cout << "n = " << n << '\n'; // 추가 모드의 출력 스트림 (C++11) std::ostringstream buf2("test", std::ios_base::ate); buf2 << '1'; std::cout << buf2.str() << '\n'; }
출력:
buf1 = 7 n = 7 n = -10 test1
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| P0935R0 | C++11 | 기본 생성자가 explicit였음 | implicit로 변경됨 |
참고 항목
|
기본 문자열 장치 객체의 내용을 가져오거나 설정합니다
(public member function) |
|
basic_stringbuf
객체를 생성합니다
(
std::basic_stringbuf<CharT,Traits,Allocator>
의 public member function)
|