No, you can't. 'x'
defines a single character or integer (note: 'ab'
is a two-byte single value [integer] made up from the ASCII values of both characters).
To include "
within a string you have two options:
- Escape the
"
with \
, as in: char foo[] = "He said \"Hello there\".";
- Use "raw strings" if the compiler is configured to support it:
char foo[] = R"(He said "Hello there".)";
Option 1 is the most portable since it doesn't require compiler support for modern C++ standards. However it's the hardest to read, especially when you get lots of escapes in the same string.
You can make it more readable by defining QUOTE:
#define QUOTE "\""
char foo[] = "He said " QUOTE "Hello there" QUOTE ".";
"
s will achieve what you want. In C, the way to escape something is with a \, so for examplechar myString[] ="\"\"";
would give you a string containing two"
s. – Mark Smith Jan 26 '17 at 15:57