October 2011
Beginner to intermediate
1200 pages
35h 33m
English
Before looking at the new listings for the String class example, let’s consider another matter. Suppose you want to copy an ordinary string to a String object. For example, suppose you use getline() to read a string and you want to place it in a String object. The class methods already allow you to do the following:
String name;char temp[40];cin.getline(temp, 40);name = temp; // use constructor to convert type
However, this might not be a satisfactory solution if you have to do it often. To see why, let’s review how the final statement works:
1. The program uses the String(const char *) constructor to construct a temporary String object containing a copy of the string stored in temp. Remember from Chapter ...
Read now
Unlock full access