Skip to main content

stringalg.cpp


// Demonstration of how algorithms can be applied to strings
// (NDE, 2014-01-07)
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  string text;
  cout << "Enter some text below:\n";
  getline(cin, text);
  string::iterator i = remove(text.begin(), text.end(), 'e');
  text.erase(i, text.end());
  cout << "e removed : " << text << endl;
  reverse(text.begin(), text.end());
  cout << "Reversed  : " << text << endl;
  sort(text.begin(), text.end());
  cout << "Sorted    : " << text << endl;
  return 0;
}