C++ Tutorial/string/string sort

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Sort all characters inside the string

<source lang="cpp">#include <string>

  1. include <iostream>
  2. include <algorithm>

using namespace std; int main() {

   const string hello("Hello, how are you?");
   string s(hello.begin(),hello.end());
   // iterate through all of the characters
   string::iterator pos;
   for (pos = s.begin(); pos != s.end(); ++pos) {
       cout << *pos;
   }
   cout << endl;
   
   sort (s.begin(), s.end());
   cout << "ordered:       " << s << endl;

}</source>

Hello, how are you?
ordered:          ,?Haeehlloooruwy