C++ strstream Write
#include <iostream> #include <strstream> #include <iomanip> using namespace std; int main()/*w w w . j av a2s. com*/ { const int MAXCHARS = 81; // one more than max characters in a line int units = 10; double price = 36.85; char buf[MAXCHARS]; strstream inmem(buf, MAXCHARS, ios::out); // open in-memory stream // Write to the buffer through the stream inmem << "No. of units = " << setw(3) << units << " Price per unit = $" << setw(6) << setprecision(2) << fixed << price << '\0'; cout << '|' << buf << '|'; cout << endl; return 0; }