//-------------------------------------------------------------------------
//
// string-io.cpp
//
// Written by:    Elizabeth Sklar, Simon Parsons
// Last modified: 10th October 2007
//
// A program to illustrate the use of string stream for I/O.
//
//-------------------------------------------------------------------------

// We need iostream for cin, cout and sstream for the stringstream objects

#include <iostream>
#include <sstream>
using namespace std;

int main() {

#define MAXBUF 10  
  char buf[MAXBUF] = "";                       // Need to initialise buf
  char c;
  istringstream instring( "my test string" );
  ostringstream outstring;
  ostringstream outstring2( buf,ios::app );

  // Input is read from "instring"

  instring >> c;
  cout << "c=[" << c << "]\n";

  // Output is written to "outstring" and "outstring2", and then ouput
  // using cout.

  outstring << c;
  outstring << c;
  cout << "outstring=[" << outstring.str() << "]\n";

  outstring2 << 'A';
  outstring2 << 'B';
  outstring2 << 'C';
  outstring2 << "DEF";
  cout << "outstring2=[" << outstring2.str() << "]\n";
}
// End of main()
