Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

standards question about multi line string constants

6 views
Skip to first unread message

catphive

unread,
Aug 7, 2007, 4:18:06 AM8/7/07
to
I've seen a few obscure syntaxes for specifying string constants, and
I want to ask which ones are in the c++ standard and which are not.

1. Concatenating string literas like so:

char* str = "first" "second" "third"
"forth" "etc";

2. Multiline strings like so

char* str = "a multi line string without
a back slash before the newline";

which on the compilers I've seen has the behavior of inserting a
newline between "without" and "a" in str as if \n had been typed there.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Seungbeom Kim

unread,
Aug 7, 2007, 10:37:13 AM8/7/07
to
catphive wrote:
> I've seen a few obscure syntaxes for specifying string constants, and
> I want to ask which ones are in the c++ standard and which are not.
>
> 1. Concatenating string literas like so:
>
> char* str = "first" "second" "third"
> "forth" "etc";

Defined to be valid by the standard (2.13.4/3): "adjacent [narrow/wide]
string literals are concatenated."

> 2. Multiline strings like so
>
> char* str = "a multi line string without
> a back slash before the newline";
>
> which on the compilers I've seen has the behavior of inserting a
> newline between "without" and "a" in str as if \n had been typed there.

Defined to be invalid by the standard (2.13.4): a /string-literal/
consists of a sequence of /s-char/'s, from which the double-quote ",
backslash \, or new-line character is explicitly excluded.

--
Seungbeom Kim

0 new messages