4.8 KiB
[quoted.manip]
31 Input/output library [input.output]
31.7 Formatting and manipulators [iostream.format]
31.7.9 Quoted manipulators [quoted.manip]
[Note 1:
Quoted manipulators provide string insertion and extraction of quoted strings (for example, XML and CSV formats).
Quoted manipulators are useful in ensuring that the content of a string with embedded spaces remains unchanged if inserted and then extracted via stream I/O.
â end note]
template<class charT> unspecified quoted(const charT* s, charT delim = charT('"'), charT escape = charT('\\')); template<class charT, class traits, class Allocator> unspecified quoted(const basic_string<charT, traits, Allocator>& s, charT delim = charT('"'), charT escape = charT('\\')); template<class charT, class traits> unspecified quoted(basic_string_view<charT, traits> s, charT delim = charT('"'), charT escape = charT('\\'));
Returns: An object of unspecified type such that if out is an instance of basic_ostream with member type char_type the same ascharT and with member type traits_type, which in the second and third forms is the same as traits, then the expressionout << quoted(s, delim, escape) behaves as a formatted output function of out.
This forms a character sequence seq, initially consisting of the following elements:
-
delim.
-
Each character in s. If the character to be output is equal toescape or delim, as determined by traits_type::eq, first output escape.
-
delim.
Let x be the number of elements initially in seq.
Then padding is determined for seq as described in [ostream.formatted.reqmts], seq is inserted as if by callingout.rdbuf()->sputn(seq, n), where n is the larger ofout.width() and x, and out.width(0) is called.
The expression out << quoted(s, delim, escape) has typebasic_ostream<charT, traits>& and value out.
template<class charT, class traits, class Allocator> unspecified quoted(basic_string<charT, traits, Allocator>& s, charT delim = charT('"'), charT escape = charT('\\'));
Returns: An object of unspecified type such that:
-
If in is an instance of basic_istream with member typeschar_type and traits_type the same as charT and traits, respectively, then the expressionin >> quoted(s, delim, escape) behaves as if it extracts the following characters from in usingoperator>>(basic_istream<charT, traits>&, charT&) ([istream.extractors]) which may throw ios_base::failure ([ios.failure]):
extract characters from in and append them to s, except that if an escape is reached, ignore it and append the next character tos.
+
[(3.1.1.4)](#3.1.1.4)
Discard the final delim character[.](#3.1.1.4.sentence-1)
+
[(3.1.1.5)](#3.1.1.5)
Restore the skipws flag to its original value[.](#3.1.1.5.sentence-1)
-
If out is an instance of basic_ostream with member typeschar_type and traits_type the same as charT andtraits, respectively, then the expressionout << quoted(s, delim, escape) behaves as specified for theconst basic_string<charT, traits, Allocator>& overload of thequoted function.
-
The expression in >> quoted(s, delim, escape) has typebasic_istream<charT, traits>& and value in.
-
The expression out << quoted(s, delim, escape) has typebasic_ostream<charT, traits>& and value out.