#include <string>
#include <vector>
#include <algorithm>
#include <iostream.h>

int
main()
{

  string a("abcdefghijklmnopqrstuvwxyz");
  string x = "cs.hmc.edu";
  string y(a,6);
  string z("abcdefghijklmnopqrstuvwxyz",6);
  string w(3,'w');
  string b = w + '.' + x;

  cout << "a is   " << a << endl;
  cout << "x is   " << x << endl;
  cout << "y is   " << y << endl;
  cout << "z is   " << z << endl;
  cout << "w is   " << w << endl;
  cout << "b is   " << b << endl;

  /* a way to access chars             */ 
  for (int j=0 ; j<a.size() ; ++j)
    cout << "   char " << j << " is " << a[j] << endl;

  /* or convert to a C-style char*     */
  const char* c = b.c_str();
  cout << "c is " << c << endl;

  /* sorting with the vector class     */
  vector<string> vs;
  vs.insert(vs.begin(),a);
  vs.insert(vs.begin(),b);
  vs.insert(vs.begin(),x);
  vs.insert(vs.begin(),y);
  vs.insert(vs.begin(),z);
  cout << "vs before:\n";
  for (int j=0 ; j<vs.size() ; ++j)  cout << "  " << vs[j] << endl;
  sort(vs.begin(),vs.end());
  cout << "vs after:\n";
  for (int j=0 ; j<vs.size() ; ++j)  cout << "  " << vs[j] << endl;

  /* example of find and replace       */
  a.replace(a.find("hi"),3,"-howdy-");       // rfind is also available
  cout << "a is   " << a << endl;            // or the C library's strstr

  /* finding from groups of characters */
  cout << "a.find_first_of(\"why\") is   " << a.find_first_of("why") << endl;
  cout << "a.find_last_of(\"why\") is   " << a.find_last_of("why") << endl;

  /* also, try find_first_not_of and find_last_not_of -- but watch out... */
  cout << "a.find_first_of(\"!?%$#\") is   " << a.find_first_of("!?%$#") << endl;
  /* may want to use the C calls       */
  cout << "strcspn(a.c_str(),\"!?%$#\") is   " << strcspn(a.c_str(),"!?%$#") << endl;
  cout << "strspn(a.c_str(),\"!?%$#\") is   " << strspn(a.c_str(),"!?%$#") << endl;

  /* extracting substrings             */
  cout << "a.substr(4,10) is   " << a.substr(4,10) << endl;
  cout << "a.substr(10,4) is   " << a.substr(10,4) << endl;

  /* removing parts of a string        */
  cout << "a before erasing is   " << a << endl;
  a.erase(10,8);
  cout << "a after erasing  is   " << a << endl;


  return 0;
}



