The new stream classes (iostream, fstream, sstream) can be used convert data to a C++ string for output to standard output, a file, or to a string.
Is this efficient? Are there alternatives?
The C I/O library also can be used to convert data to C-strings
The output C functions are
- printf - output to standard output
- fprintf - output to a file
- sprintf - output to a string
The sprintf function is typically much faster than using a stringstream!
On the other hand, sprintf can only be used with basic types, not class types. While stringstream can be used with any class type, provided operator<< has been overloaded for values of that class type.
On the other, other hand, conversions to string of complicated classes may not be needed in many kinds of applications.