The IString class defines an addition operator (+) to allow you to concatenate two words together. An addition assignment operator (+=) lets you assign the result of the concatenation to the left operand. The copy() member function lets you create an IString consisting of multiple copies of itself or of another string. The following example shows ways of concatenating text onto the start or end of an IString:
// Concatenating strings
#include <iostream.h> #include <istring.hpp>
void main() {
IString Str1="Let ";
IString Str2="us ";
IString Str3="concatenate ";
IString Str4="repeatedly ";
IString Str5=Str1+Str2; // Add Str1 and Str2 and store in Str5 Str5+=Str3; // Add Str3 to Str5 Str4.copy(3); // Copy Str4 several times onto itself Str5+=Str4; // Add Str4 to Str5 cout << Str5 << endl; // Write String 5 }
This program produces the following output:
Let us concatenate repeatedly repeatedly repeatedly