Template overview – HP Integrity NonStop J-Series User Manual
Page 113
Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Template Overview
To gain some perspective, let's begin with a general example that shows how templates work. We'll
explain concepts from the example throughout the section, though you'll probably follow this
without difficulty now:
#include
#include
#include
#include
int main()
{
// Declare a linked-list of strings:
RWTValDlist
RWTValDlist
RWCString sentence;
// Add words to the list:
stringList.insert("Templates");
stringList.insert("are");
stringList.insert("fun");
// Now use standard iterators to build a sentence:
iter = stringList.begin();
while (iter != stringList.end()) {
sentence += (*iter++ + " ");
}
// Replace trailing blank with some oomph!
sentence(RWCRegexp(" $")) = "!"
// Display the result:
cout << sentence << endl;
return 0;
}
Output:
Templates are fun!