std::basic_istringstream<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"
関連項目
|
基となる生文字列デバイスオブジェクトを返す
(公開メンバ関数) |
|
|
関連付けられた文字列のコピーを取得または置換する
(
std::basic_stringbuf<CharT,Traits,Allocator>
の公開メンバ関数)
|