std::basic_stringstream<CharT,Traits,Allocator>:: str
| (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 이후) |
기본 문자열 객체의 내용을 관리합니다.
목차 |
매개변수
| s | - | 기본 문자열의 새로운 내용 |
| t | - | 기본 문자열의 새로운 내용으로 사용할 객체 ( std::basic_string_view 로 변환 가능) |
| a | - | 반환된 문자열을 구성하는 데 사용할 할당자 |
반환값
참고 사항
str
에 의해 반환된 기반 문자열의 복사본은 표현식의 끝에서 소멸될 임시 객체이므로,
str
(
)
의 결과에 직접
c_str()
를 호출하는 경우(예:
auto
*
ptr
=
out.
str
(
)
.
c_str
(
)
;
) 댕글링 포인터가 생성됩니다.
| 기능 테스트 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_sstream_from_string_view
|
202306L
|
(C++26) | std::stringstream 과 std::string_view 간의 인터페이싱, ( 7 ) |
예제
#include <iostream> #include <sstream> int main() { int n; std::istringstream in; // could also use in("1 2") in.str("1 2"); in >> n; std::cout << "After reading the first int from \"1 2\", the int is " << n << ", str() = \"" << in.str() << "\"\n"; 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); 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"
참고 항목
|
기본 원시 문자열 장치 객체를 반환합니다
(public member function) |
|
|
연결된 문자열의 복사본을 교체하거나 획득합니다
(
std::basic_stringbuf<CharT,Traits,Allocator>
의
public member function)
|