// ==========================================================================
// $Id: stringstream.cpp,v 1.2 2010/10/20 14:30:46 jlang Exp $
// CSI2372 example Code for lecture 8
// ==========================================================================
// (C)opyright:
//
//   Jochen Lang
//   SITE, University of Ottawa
//   800 King Edward Ave.
//   Ottawa, On., K1N 6N5
//   Canada. 
//   http://www.site.uottawa.ca
// 
// Creator: jlang (Jochen Lang)
// Email:   jlang@site.uottawa.ca
// ==========================================================================
// $Log: stringstream.cpp,v $
// Revision 1.2  2010/10/20 14:30:46  jlang
// Added non-std algorithm compiler switch
//
// Revision 1.1  2006/10/17 22:18:48  jlang
// Added examples for lecture 8
//
//
// ==========================================================================
// #define WITH_STD_ALGORITHM

#include <string>
#include <iostream>
#include <sstream>
#ifdef WITH_STD_ALGORITHM
// transform is a std algorithm
#include <algorithm>
#endif

using namespace std;

int main() {
  string line, token;
  // Get a line
  while (getline(cin, line)) {
    istringstream streamLine(line);
    cout << "Got: " << line << endl;
    // Get individual white space separated tokens
    cout << "Tokens: " << endl;
    while ( streamLine >> token ) {
      // Process word
      cout << token << endl;
#ifdef WITH_STD_ALGORITHM
      transform( token.begin(), token.end(), token.begin(),
		 static_cast<int (*)(int)>(tolower) );
#else
      for ( int i=0; i<token.size(); ++i ) {
	token[i] = tolower( token[i] );
      }
#endif
      if ( token == "exit" ) break;
    } 
    if ( token == "exit" ) break;
  }
}
