yapkm01
yapkm01

Reputation: 3771

c++ primer 4th edition - String question

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 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?

Upvotes: 0

Views: 273

Answers (3)

eddy
eddy

Reputation: 13

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.

Upvotes: 1

debracey
debracey

Reputation: 6607

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

Upvotes: 3

Keith
Keith

Reputation: 6834

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

Upvotes: 2

Related Questions