next up previous
Next: Derived and Templated Classes Up: Classes Previous: Implementation file

Using the object

With the string class defined, we can now use string objects as first class data types. Rewriting the simple ``hello_world'' program, for example:


#include <iostream.h>
#include "mystring.h"

void main() {
    string hello("Hello");
    string world="world";
    string space;

    space = " ";

    string total(hello);
    total += space;
    total += world;

    cout << total << endl;
}

Class Exercise -


Write a short program to read in 10 words from standard input and generate two strings from the words. The first string should have all words starting with letters a-m and the second should have all strings starting with letters n-z. No error checking is required and you can assume all words are completely lower case.



Eric Breimer
9/13/1999