std::basic_stringbuf<CharT,Traits,Allocator>:: str
From cppreference.net
<
cpp
|
io
|
basic stringbuf
| (1) | ||
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
;
|
(C++20 이전) | |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
const
&
;
|
(C++20 이후) | |
|
template
<
class
SAlloc
>
std:: basic_string < CharT, Traits, SAlloc > str ( const SAlloc & a ) const ; |
(2) | (C++20 이후) |
|
std::
basic_string
<
CharT, Traits, Allocator
>
str
(
)
&&
;
|
(3) | (C++20 이후) |
|
void
str
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s
)
;
|
(4) | |
|
template
<
class
SAlloc
>
void str ( const std:: basic_string < CharT, Traits, SAlloc > & s ) ; |
(5) | (C++20 이후) |
|
void
str
(
std::
basic_string
<
CharT, Traits, Allocator
>
&&
s
)
;
|
(6) | (C++20 이후) |
|
template
<
class
StringViewLike
>
void str ( const StringViewLike & t ) ; |
(7) | (C++26 이후) |
기본 문자열을 가져오고 설정합니다.
아래 설명에서, buf 와 mode 는 설명 전용 데이터 멤버 입니다. * this 의.
1)
이
std::basic_stringbuf
의 내부 문자 시퀀스 복사본을 포함하는
std::basic_string
객체를 생성하고 반환합니다. 입력 전용 스트림의 경우, 반환된 문자열은
[
eback()
,
egptr()
)
범위의 문자들을 포함합니다. 입출력 또는 출력 전용 스트림의 경우,
pbase()
부터 시퀀스의 마지막 문자까지의 문자들을
egptr()
및
epptr()
과 관계없이 포함합니다.
-
-
쓰기용으로 열린 버퍼의 멤버 문자 시퀀스는 효율성을 위해 초과 할당될 수 있습니다. 이 경우
초기화된 문자들
만 반환됩니다: 이러한 문자들은 생성자의 문자열 인수,
str()의 setter 오버로드에 대한 가장 최근 호출의 문자열 인수, 또는 쓰기 작업으로부터 얻은 문자들입니다. 초과 할당을 사용하는 일반적인 구현은 버퍼의 초기화된 부분의 끝을 추적하기 위해 high-watermark 포인터를 유지하며, 이 오버로드는 pbase() 부터 high-watermark 포인터까지의 문자들을 반환합니다.
-
쓰기용으로 열린 버퍼의 멤버 문자 시퀀스는 효율성을 위해 초과 할당될 수 있습니다. 이 경우
초기화된 문자들
만 반환됩니다: 이러한 문자들은 생성자의 문자열 인수,
|
(C++20부터) |
2)
(1)
과 동일하지만,
a
가 반환되는
std::basic_string
을 구성하는 데 사용됩니다. 다음 코드와 동등합니다:
return
std::
basic_string
<
CharT, Traits, SAlloc
>
(
view
(
)
, a
)
;
.
3)
std::basic_string
객체를 마치
*
this
의 내부 문자 시퀀스에서 이동 생성하는 것처럼 생성합니다.
buf
는 처음에
(1)
과 동일한 내용을 포함하도록 조정될 필요가 있을 수 있습니다. 이후
buf
를 비우고
init_buf_ptrs
()
를 호출한 다음,
std::basic_string
객체를 반환합니다.
5)
(4)
와 동일하지만,
s
의 할당자 타입이
Allocator
가 아닌 경우입니다.
7)
암시적으로
t
를 문자열 뷰
sv
로 변환하며, 마치
std::
basic_string_view
<
CharT, Traits
>
sv
=
t
;
와 같이 수행한 후, 내부 문자 시퀀스를 마치
buf
=
sv
와 같이 교체하고,
init_buf_ptrs
()
를 호출합니다.
이 오버로드는 다음 조건이
std::
is_convertible_v
<
const
StringViewLike
&
,
std:: basic_string_view < CharT, Traits >> 일 때만 오버로드 해결에 참여합니다.
std:: basic_string_view < CharT, Traits >> 일 때만 오버로드 해결에 참여합니다.
목차 |
매개변수
| s | - | 대체 문자 시퀀스를 담고 있는 std::basic_string 객체 |
| t | - | 대체 문자 시퀀스를 담고 있는 객체 ( std::basic_string_view 로 변환 가능한) |
| a | - | 반환되는 std::basic_string 의 모든 메모리 할당에 사용할 할당자 |
반환값
1-3)
이 버퍼의 기본 문자 시퀀스를 보유하는
std::basic_string
객체입니다.
4-7)
(없음)
참고 사항
이 함수는 일반적으로 std::basic_istringstream::str() , std::basic_ostringstream::str() , 또는 std::basic_stringstream::str() 를 통해 접근됩니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | 문자열 스트림과 std::string_view 연동 |
예제
이 코드 실행
#include <iostream> #include <sstream> int main() { int n; std::istringstream in; // could also use in("1 2") in.rdbuf()->str("1 2"); // set the get area in >> n; std::cout << "after reading the first int from \"1 2\", the int is " << n << ", str() = \"" << in.rdbuf()->str() << "\"\n"; // or in.str() std::ostringstream out("1 2"); out << 3; std::cout << "after writing the int '3' to output stream \"1 2\"" << ", str() = \"" << out.str() << "\"\n"; std::ostringstream ate("1 2", std::ios_base::ate); // C++11 ate << 3; std::cout << "after writing the int '3' to append stream \"1 2\"" << ", str() = \"" << ate.str() << "\"\n"; }
출력:
after reading the first int from "1 2", the int is 1, str() = "1 2" after writing the int '3' to output stream "1 2", str() = "3 2" after writing the int '3' to append stream "1 2", str() = "1 23"
결함 보고서
다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 432 | C++98 |
1. 오버로드
(1)
이 기본 문자 시퀀스의 내용을
명시하지 않음 2. 오버로드 (4) 이 입력 및 출력 시퀀스 초기화 방식을 명시하지 않음 |
모두 명시됨 |
| LWG 562 | C++98 |
오버로드
(4)
가
epptr()
을 마지막 기본 문자의 다음 위치를
가리키도록 설정함 (if bool ( mode & std:: ios_base :: out ) == true 인 경우) |
epptr()
을 해당 위치
너머로 설정 가능 |
참고 항목
|
기본 문자열 장치 객체의 내용을 가져오거나 설정함
(
std::basic_stringstream<CharT,Traits,Allocator>
의 public member function)
|
|
|
(C++20)
|
기본 문자 시퀀스에 대한 뷰를 획득함
(public member function) |