c++ - Is there a way to put quotes in a cout? -
this question has answer here:
i trying make simple calculator , display quotes in instruction when first run program.
another solution use raw strings:
#include <string> #include <iostream> int main() { std::cout << r"_(a raw string " inside (and \ well))_" << std::endl; return 0; }
output:
a raw string " inside (and \ well)
quotes standard:
according standard 2.14.5 [lex.string]:
string-literal: encoding-prefixopt "s-char-sequenceopt" encoding-prefixopt r raw-string encoding-prefix: u8 u u l s-char-sequence: s-char s-char-sequence s-char s-char: member of source character set except double-quote ", backslash \, or new-line character escape-sequence universal-character-name raw-string: " d-char-sequenceopt ( r-char-sequenceopt) d-char-sequenceopt " r-char-sequence: r-char r-char-sequence r-char r-char: member of source character set, except right parenthesis ) followed initial d-char-sequence (which may empty) followed double quote ". d-char-sequence: d-char d-char-sequence d-char d-char: member of basic source character set except: space, left parenthesis (, right parenthesis ), backslash \, , control characters representing horizontal tab, vertical tab, form feed, , newline.
a string literal sequence of characters (as defined in 2.14.3) surrounded double quotes, optionally prefixed
r
,u8
,u8r
,u
,ur
,u
,ur
,l
, orlr
, in"..."
,r"(...)"
,u8"..."
,u8r"**(...)**"
,u"..."
,ur"*˜(...)*˜"
,u"..."
,ur"zzz(...)zzz"
,l"..."
, orlr"(...)"
, respectively.a string literal has
r
in prefix raw string literal.d-char-sequence
serves delimiter. terminatingd-char-sequence
of raw-string same sequence of characters initiald-char-sequence
.d-char-sequence
shall consist of @ 16 characters.- [note: characters
(
,)
permitted in raw-string. thus,r"delimiter((a|b))delimiter"
equivalent"(a|b)"
. —end note ][note: source-file new-line in raw string literal results in new-line in resulting execution
string-literal
. assuming no whitespace @ beginning of lines in following example, assert succeed:const char *p = r"(a\ b c)"; assert(std::strcmp(p, "a\\\nb\nc") == 0);
— end note ]
[example: raw string
r"a( )\ a" )a"
is equivalent
"\n)\\\na\"\n"
. raw stringr"(??)"
is equivalent
"\?\?"
. raw stringr"#( )??=" )#"
is equivalent
"\n)\?\?=\"\n"
. —end example ]
Comments
Post a Comment