New adopted paper: N3654, Quoted Strings Library Proposal (Revision 2) -- Beman Dawes

Note: This paper was adopted into draft C++14 on Saturday at the Bristol UK ISO C++ meeting.

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3654

Date: 2013-04-19

Quoted Strings Library Proposal (Revision 2)

by Beman Dawes


The proposed quoted stream I/O manipulator places delimiters, defaulted to double-quote ("), around strings on output, and strips off the delimiters on input. This ensures strings with embedded white space round-trip as desired. For example,

std::stringstream ss;
std::string original = "foolish me";
std::string round_trip;

ss << quoted(original);
ss >> quoted(round_trip);

std::cout << original;     // outputs: foolish me
std::cout << round_trip;   // outputs: foolish me

assert(original == round_trip); // assert will not fire

If the string contains the delimiter character, on output that character will be preceded by an escape character, default to backslash (\), as will the escape character itself:

std::cout << quoted("She said \"Hi!\"");  // outputs: "She said \"Hi!\""


Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.