Next: String Input Up: Strings in C++ Previous: Strings in C++

String Output

A string is output by sending it to an output stream, for example:

cout << "The string s1 is " << s1 << endl;
would print
The string s1 is example

The setw(width) I/O manipulator can be used before outputting a string, the string will then be output right-justified in the field width. If the field width is less than the length of the string then the field width will be expanded to fit the string exactly. If the string is to be left-justified in the field then the setiosflags manipulator with the argument ios::left can be used.



Next: String Input Up: Strings in C++ Previous: Strings in C++