Saturday, June 14, 2008

Accelerated C++ Chapter 1 - Working with Strings

The Page continues the discussion of Accelerated C++: Practical Programming by Example (C++ In-Depth Series)

Chapter 1 immediately introduces the reader to an object by modifying the Hello World program from chapter 0 to ask the user for his name then saying Hello [user].

using namespace std;
int main() {
cout << "Enter Name: " <> name;

string name;
cin >> name;

cout << "Hello " << name << endl;
return 0;

Once again this simple example introduces a lot of new concept. Were introduced to variables, objects,definitions, interfaces, initialization, and the string object.

The String object is the most important concept from this chapter. By using it the reader is introduced to the constructor, and the idea of an interface for the object. For example the reader can now time name.size() to get the size of the object. This new knowledge is put to use to frame the name with a series of asteriks leading to the close of Chapter 1.

No comments: