12345678910111213141516171819202122232425 |
- // strout.cpp -- incore formatting (output)
- #include <iostream>
- #include <sstream>
- #include <string>
- int main()
- {
- using namespace std;
- ostringstream outstr; // manages a string stream
- string hdisk;
- cout << "What's the name of your hard disk? ";
- getline(cin, hdisk);
- int cap;
- cout << "What's its capacity in GB? ";
- cin >> cap;
- // write formatted information to string stream
- outstr << "The hard disk " << hdisk << " has a capacity of "
- << cap << " gigabytes.\n";
- string result = outstr.str(); // save result
- cout << result; // show contents
- // cin.get();
- // cin.get();
- return 0;
- }
|