| I/O manipulators | ||||
| Print functions(C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++20) | ||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
(C++98/26*) | ||||
| Synchronized Output | ||||
(C++20) | ||||
| Types | ||||
| Error category interface | ||||
(C++11) | ||||
(C++11) |
| Floating-point formatting | |||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||
| Integer formatting | |||||||||||||||||||||||||||||||
| Boolean formatting | |||||||||||||||||||||||||||||||
| Field width and fill control | |||||||||||||||||||||||||||||||
| Other formatting | |||||||||||||||||||||||||||||||
| Whitespace processing | |||||||||||||||||||||||||||||||
| Output flushing | |||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
| Status flags manipulation | |||||||||||||||||||||||||||||||
| Time and money I/O | |||||||||||||||||||||||||||||||
| Quoted manipulator | |||||||||||||||||||||||||||||||
quoted (C++14) | |||||||||||||||||||||||||||||||
Defined in header <iomanip> | ||
template<class CharT> /*unspecified*/ quoted(const CharT* s, | (1) | (since C++14) |
template<class CharT,class Traits,class Allocator> /*unspecified*/ quoted(conststd::basic_string<CharT, Traits, Allocator>& s, | (2) | (since C++14) |
template<class CharT,class Traits> /*unspecified*/ quoted(std::basic_string_view<CharT, Traits> s, | (3) | (since C++17) |
template<class CharT,class Traits,class Allocator> /*unspecified*/ quoted(std::basic_string<CharT, Traits, Allocator>& s, | (4) | (since C++14) |
Allows insertion and extraction of quoted strings, such as the ones found inCSV orXML.
out is an output stream withchar_type equal toCharT and, for overloads (2,3),traits_type equal toTraits, behaves as aFormattedOutputFunction, which inserts intoout a sequence of charactersseq constructed as follows:seq once more.in is an input stream withchar_type equal toCharT andtraits_type equal toTraits, extracts characters fromin, usingstd::basic_istream::operator>>, according to the following rules:traits_type::eq), then simply performsin>> s.in and appends them tos, except that whenever anescape character is extracted, it is ignored and the next character is appended tos. Extraction stops when!in==true or when an unescapeddelim character is found.Contents |
| s | - | the string to insert or extract |
| delim | - | the character to use as the delimiter, defaults to" |
| escape | - | the character to use as the escape character, defaults to\ |
Returns an object of unspecified type such that the described behavior takes place.
Throwsstd::ios_base::failure ifoperator>> oroperator<< throws.
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_quoted_string_io | 201304L | (C++14) | std::quoted |
#include <iomanip>#include <iostream>#include <sstream> void default_delimiter(){conststd::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(){constchar delim{'$'};constchar escape{'%'}; conststd::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();}
Output:
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) | stores formatted representation of the arguments in a new string (function template)[edit] |