August 2002
Beginner
1122 pages
22h 1m
English
Now it's time to get back to our discussion of stringstream. A stringstream is very similar to an ostream, except that once we have written data to a stringstream, we can read it from the stringstream into a variable just as though we were reading from a file or the keyboard. An example is the program shown in Figure 9.20, which uses a stringstream object to combine a year, month, and day number to make one string containing all of those values.
#include <iostream> #include <sstream> using namespace std; int main() { stringstream FormatStream; string date; short year = 1996; short month = 7; short day = 28; FormatStream << year; FormatStream << month; FormatStream ... |
Read now
Unlock full access