2011-03-28 50 views
0

我在閱讀本書中的第86頁關於字符串和文字,我不明白爲什麼它說下面關於字符串s1和s2。C++ primer第4版 - 字​​符串問題

string s1("hello, "); 
string s2("world\n"); 
string s3 = s1+s2; 
.. 

它說s1s2直接包含標點符號。標點?什麼標點符號。另外87

string s1 = "hello"; // no punctuation. Again what punctuation? 

任何人都可以解釋一下嗎?

+0

s3將是「你好,世界\ n」,其中\ n是一個新行 - 標點符號是',' – 2011-03-28 00:41:11

+0

有些語言學家肯定寫過這個人。 – julkiewicz 2011-03-28 00:44:13

+1

@ yapkm01:當你在閱讀本書時,我們是否應該期待未來的問題? – phooji 2011-03-28 00:51:27

回答

3

我真的進去看了一下這本書。作者正在考慮將「,」和「\ n」作爲「標點符號」。

86頁上的第二天一句說:

The strings s1 and s2 included punctuation directly. 
We could achieve the same result by mixing string objects 
and string literals as follows: 

string s1("hello"); 
string s2("world"); 
string s3 = s1 + ", " + s2 + "\n"; 

- 丹

2

想必筆者的意思是逗號,和換行\n是標點符號。

1

Keith的和傑森的回答是正確的參照「逗號」標點符號。在s1中,「,」包含在「hello」中。這也可以寫成: string s3 = s1 +「,」+ s2 +「\ n」;分隔標點符號

編輯 - 看起來像丹已經發布了相同的答案。