std:: quoted
|
ヘッダーで定義
<iomanip>
|
||
|
template
<
class
CharT
>
/*unspecified*/
quoted
(
const
CharT
*
s,
|
(1) | (C++14以降) |
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
/*unspecified*/
quoted
(
const
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(2) | (C++14以降) |
|
template
<
class
CharT,
class
Traits
>
/*unspecified*/
quoted
(
std::
basic_string_view
<
CharT, Traits
>
s,
|
(3) | (C++17以降) |
|
template
<
class
CharT,
class
Traits,
class
Allocator
>
/*unspecified*/
quoted
(
std::
basic_string
<
CharT, Traits, Allocator
>
&
s,
|
(4) | (C++14以降) |
CSVや CSV または XML で見られるような引用符付き文字列の挿入と抽出を可能にします。
out
は
char_type
が
CharT
と等しい出力ストリームであり、オーバーロード(2,3)については
traits_type
が
Traits
と等しい場合、
FormattedOutputFunction
として振る舞い、以下のように構築された文字シーケンス
seq
を
out
に挿入します:
seq
に再度追加されます。
- 次に、 seq. size ( ) < out. width ( ) の場合、 out. width ( ) - seq. size ( ) 個のフィル文字 out. fill ( ) を追加します。これは、 out. flags ( ) で ios_base :: left が設定されている場合はシーケンスの末尾に、それ以外の場合はシーケンスの先頭に追加されます。
- 最終的に、結果のシーケンスから各文字を、以下のように呼び出すかのように出力します out. rdbuf ( ) - > sputn ( seq, n ) 。ここで n = std:: max ( out. width ( ) , seq. size ( ) ) であり、 out. width ( 0 ) を呼び出して std::setw の効果があればそれを解除します。
in
は
char_type
が
CharT
と等しく、
traits_type
が
Traits
と等しい入力ストリームであり、以下の規則に従って
in
から文字を抽出します:
std::basic_istream::operator>>
を使用して:
traits_type::eq
によって判定)、単に
in
>>
s
を実行します。
in
から連続する文字を抽出し、それらを
s
に追加します。ただし、
escape
文字が抽出された場合は無視され、次の文字が
s
に追加されます。抽出は
!
in
==
true
の場合、またはエスケープされていない
delim
文字が見つかった場合に停止します。
目次 |
パラメータ
| s | - | 挿入または抽出する文字列 |
| delim | - | 区切り文字として使用する文字(デフォルトは " ) |
| escape | - | エスケープ文字として使用する文字(デフォルトは \ ) |
戻り値
記述された動作が行われるように、不特定の型のオブジェクトを返します。
例外
std::ios_base::failure が送出される条件: operator >> または operator << が例外を送出した場合。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_quoted_string_io
|
201304L
|
(C++14) |
std::quoted
|
例
#include <iomanip> #include <iostream> #include <sstream> void default_delimiter() { const std::string in = "std::quoted() quotes this string and embedded \"quotes\" too"; std::stringstream ss; ss << std::quoted(in); std::string out; ss >> std::quoted(out); std::cout << "Default delimiter case:\n" "read in [" << in << "]\n" "stored as [" << ss.str() << "]\n" "written out [" << out << "]\n\n"; } void custom_delimiter() { const char delim{'$'}; const char escape{'%'}; const std::string in = "std::quoted() quotes this string and embedded $quotes$ $too"; std::stringstream ss; ss << std::quoted(in, delim, escape); std::string out; ss >> std::quoted(out, delim, escape); std::cout << "Custom delimiter case:\n" "read in [" << in << "]\n" "stored as [" << ss.str() << "]\n" "written out [" << out << "]\n\n"; } int main() { default_delimiter(); custom_delimiter(); }
出力:
Default delimiter case: read in [std::quoted() quotes this string and embedded "quotes" too] stored as ["std::quoted() quotes this string and embedded \"quotes\" too"] written out [std::quoted() quotes this string and embedded "quotes" too] Custom delimiter case: read in [std::quoted() quotes this string and embedded $quotes$ $too] stored as [$std::quoted() quotes this string and embedded %$quotes%$ %$too$] written out [std::quoted() quotes this string and embedded $quotes$ $too]
関連項目
|
(C++20)
|
引数のフォーマットされた表現を新しい文字列に格納する
(関数テンプレート) |