strout.cpp 672 B

12345678910111213141516171819202122232425
  1. // strout.cpp -- incore formatting (output)
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. int main()
  6. {
  7. using namespace std;
  8. ostringstream outstr; // manages a string stream
  9. string hdisk;
  10. cout << "What's the name of your hard disk? ";
  11. getline(cin, hdisk);
  12. int cap;
  13. cout << "What's its capacity in GB? ";
  14. cin >> cap;
  15. // write formatted information to string stream
  16. outstr << "The hard disk " << hdisk << " has a capacity of "
  17. << cap << " gigabytes.\n";
  18. string result = outstr.str(); // save result
  19. cout << result; // show contents
  20. // cin.get();
  21. // cin.get();
  22. return 0;
  23. }