A small query - example code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int _tmain(int argc, _TCHAR* argv[])
{
	string front;
	string back;
	string text = "Always laugh when you can.  It\'s cheap medicine.";
	// Add more statements here.
	front.assign(text);
	cout << endl << "Front: " << front << endl;
	front.assign(text, 0, 27);
	cout << endl << "Front: " << front << endl;
	back.assign(text, 27, text.size());
	cout << "Back: " << back << endl;
	back.swap(front);
	cout << endl << "Front: " << front << endl;
	cout << "Back: " << back << endl;
	cin.get();
	return 0;
}


I made this program but I saw in a book this part:
"Always laugh when you can. It\'s cheap medicine."

Why can't I just put it as:
"Always laugh when you can. It's cheap medicine." instead?

Why has the programmer in the book done the first method instead of the latter?

Thanks.
Why can't I just put it as:
"Always laugh when you can. It's cheap medicine." instead?

You can.


Why has the programmer in the book done the first method instead of the latter?

You'd have to ask him that. There really isn't a difference between the two for practical purposes.
Topic archived. No new replies allowed.