开发者

c++ primer 4th edition - String question

开发者 https://www.devze.com 2023-02-19 23:04 出处:网络
I\'m reading page 86 in this book about string and literals and i don\'t understand why it says the following about string s1开发者_C百科 and s2.

I'm reading page 86 in this book about string and literals and i don't understand why it says the following about string s1开发者_C百科 and s2.

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

it says s1 and s2 included punctuation directly. Punctuation? What punctuation.

Also on page 87.

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

Can anyone explain?


I actually went in and looked at the book in question. The author is considering the "," and the "\n" to be "punctuation."

The very next sentence on page 86 said:

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";

-- Dan


Presumably the author means that commas , and linefeeds\n are punctuation.


Keith's and Jason's answer are correct referring to the "comma" punctuation. In s1 the "," is included with "hello". This could also be written as: string s3 = s1 + ", " + s2 + "\n"; separating the punctuation

edit-Looks like Dan already posted the same answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消