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; } 

live example

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. 
  1. 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, or lr, in "...", r"(...)", u8"...", u8r"**(...)**", u"...", ur"*˜(...)*˜", u"...", ur"zzz(...)zzz", l"...", or lr"(...)", respectively.

  2. a string literal has r in prefix raw string literal. d-char-sequence serves delimiter. terminating d-char-sequence of raw-string same sequence of characters initial d-char-sequence. d-char-sequence shall consist of @ 16 characters.

  3. [note: characters ( , ) permitted in raw-string. thus, r"delimiter((a|b))delimiter" equivalent "(a|b)". —end note ]
  4. [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 ]

  5. [example: raw string

    r"a( )\ a" )a" 

    is equivalent "\n)\\\na\"\n". raw string

    r"(??)" 

    is equivalent "\?\?". raw string

    r"#( )??=" )#" 

    is equivalent "\n)\?\?=\"\n". —end example ]


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -