about strings limitations

using 2 mark quotes, the ' " ' it's printed:
""""
prints:
"
so see these text:
"var name as string = \"hello "" world\"\n"
letter by letter how can i compare the "" ?
if((strinput[uintStringIndex]=='\"' && strinput[uintStringIndex+1]=='\"') || (strinput[uintStringIndex]=='""' && strinput[uintStringIndex+1]=='""'))
these code works fine for \", but when i use the "" isn't compared, because print's ".
so can anyone advice me?
Only '"' is correct (or '\"', but the backslash is not needed for a double quote inside single quotes).

In a string, putting two " in a row just splits the string into two parts that are "glued" back together by the compiler. That allows you to do this:

1
2
3
4
5
std::cout << "hello "
             "there "
             "my "
             "good "
             "sir\n";

All of those separate string literals are "concatenated" together at compile time into

std::cout << "hello there my good sir\n";

So the string literal(s):

"var name as string = \"hello "" world\"\n"

is really just

"var name as string = \"hello  world\"\n"

Last edited on
To add to @tpb's post:

There is such thing as a multi-character literal, which uses the single-quote characters as a delimiter.

We're used to seeing single-byte character literals,'a', 'b', '\"', etc., but it is also (syntactically) correct to put more than one character in the single quotes, like you've done here: '""'. This forms a "multi-character literal" with type int, and an implementation-defined value.
Last edited on
thank you so much for the correction
Topic archived. No new replies allowed.