-3

重複の可能性:
2つの文字列リテラルの連結

ケース1 "hello" "world"(エラーなし)

ケース2 "hello"+"world"(エラー)

+演算子は、オペランドの1つをではstring typeなく、として持つ必要があることを私は知っていstring literalます。

どちらの場合も意味がありません。これをsingle literal!に含めることができるからです。

なぜケース1が許可されるのですか?

4

2 に答える 2

5

C ++は基本的に隣接するリテラルを同じリテラルと見なすため、ケース1が許可されます。つまり、コードは解析の早い段階で"hello" "world"変換されます。"helloworld"

于 2012-09-20T09:48:17.387 に答える
0

Case 1, as you call it, is a convenient way to let string constants span several lines or be broken up into easily identified parts.

It's there to make your life easier.

Assuming that + should have the same semantics when used with string constants is a mistake. Especially in C, where string isn't an available type.

于 2012-09-20T09:50:05.290 に答える