-3

I was trying to make a simple calculator and I would like to display quotes in the instruction when you first run the program.

user5787634
  • 1
  • 1
  • 2
  • I assume you've just started with C++? I feel this question is more suited for Google than StackOverflow. – swinefish Jan 21 '16 at 07:14

2 Answers2

4

Use \". Also known as escape sequences.

skypjack
  • 49,335
  • 19
  • 95
  • 187
4

Another solution is to use raw strings:

#include <string>
#include <iostream>

int main()
{
    std::cout << R"_(A raw string with " inside (and \ as well))_" << std::endl;
    return 0;
}

Live example

Output:

A raw string with " inside (and \ as well)


Quotes from the Standard:

According to the 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:
    any member of the source character set except
        the 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:
    any member of the source character set, except
        a right parenthesis ) followed by the initial d-char-sequence
        (which may be empty) followed by a double quote ".

d-char-sequence:
    d-char
    d-char-sequence d-char

d-char:
    any member of the basic source character set except:
        space, the left parenthesis (, the right parenthesis ), the backslash \,
        and the control characters representing horizontal tab,
        vertical tab, form feed, and newline.
  1. A string literal is a sequence of characters (as defined in 2.14.3) surrounded by double quotes, optionally prefixed by R, u8, u8R, u, uR, U, UR, L, or LR, as in "...", R"(...)", u8"...", u8R"**(...)**", u"...", uR"*˜(...)*˜", U"...", UR"zzz(...)zzz", L"...", or LR"(...)", respectively.

  2. A string literal that has an R in the prefix is a raw string literal. The d-char-sequence serves as a delimiter. The terminating d-char-sequence of a raw-string is the same sequence of characters as the initial d-char-sequence. A d-char-sequence shall consist of at most 16 characters.

  3. [Note: The characters ( and ) are permitted in a raw-string. Thus, R"delimiter((a|b))delimiter" is equivalent to "(a|b)". —end note ]
  4. [Note: A source-file new-line in a raw string literal results in a new-line in the resulting execution string-literal. Assuming no whitespace at the beginning of lines in the following example, the assert will succeed:

    const char *p = R"(a\
    b
    c)";
    assert(std::strcmp(p, "a\\\nb\nc") == 0);
    

    — end note ]

  5. [Example: The raw string

    R"a(
    )\
    a"
    )a"
    

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

    R"(??)"
    

    is equivalent to "\?\?". The raw string

    R"#(
    )??="
    )#"
    

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

awesoon
  • 32,469
  • 11
  • 74
  • 99