簡體   English   中英

c ++字符串文字並置

[英]c++ string literal concatenation by juxtaposition

編碼

std::string str = "Hello " "world";
std::cout << str << std::endl;

編譯並打印Hello world 同樣,

char chr[] = "abc" "def" "ghi";
std::cout << chr << std::endl;

打印abcdefghi 這如何以及為什么起作用?

這是[lex.phases] / 6涵蓋的行為

相鄰的字符串文字標記是串聯在一起的。

因此,在編譯器實際開始編譯代碼之前,僅將所有字符串文字分隔開,為什么將空格連接在一起。

"hello " "world";
"hello "                  "world";
"hello " 
"world";

全部產生"hello world";

僅由空格分隔的字符串文字會自動連接起來, 請參閱cppreference

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM