construct a table of circular areas : ostrstream « File « C++






construct a table of circular areas

  
#include <iostream>
#include <sstream>
#include <locale>
#include <iomanip>

using namespace std;

int main()
{
  locale usloc("English_US");

  ostringstream ostr;

  // Give a new, empty string to ostr.
  ostr.str(string());

  // construct a table of circular areas.
  ostr << setprecision(4) << showpoint << fixed << left;
  ostr << "Diameter    Area\n";

  cout << "A table of circular areas.\n";
  for(int i=1; i < 10; ++i)
    ostr << left << "   " << setw(6) << i << setw(8) << right << i*3.1416 << endl;

  cout << ostr.str();

  return 0;
}
  
    
  








Related examples in the same category

1.Freeze dynamic buffer and return pointer to it
2.Display the contents of strin via calls to get()
3.use the contents of strout to create strin