Is there any STL function for sorting characters inside a string?

Discussion in 'C++' started by Lambda, Sep 4, 2007.

  1. Lambda

    Lambda Guest

    I'm looking for a STL function to sort characters inside a string,
    like:

    string_sort("disprove") => "deioprsv".
     
    Lambda, Sep 4, 2007
    #1
    1. Advertising

  2. Lambda

    Barry Guest

    Lambda wrote:
    > I'm looking for a STL function to sort characters inside a string,
    > like:
    >
    > string_sort("disprove") => "deioprsv".
    >

    #include <iostream>
    #include <string>
    #include <algorithm>

    int main()
    {
    std::string str("disprove");
    std::sort(str.begin(), str.end());
    std::cout << str << std::endl;
    }
     
    Barry, Sep 4, 2007
    #2
    1. Advertising

  3. Lambda

    Lambda Guest

    On Sep 4, 9:28 am, Barry <> wrote:
    > Lambda wrote:
    > > I'm looking for a STL function to sort characters inside a string,
    > > like:

    >
    > > string_sort("disprove") => "deioprsv".

    >
    > #include <iostream>
    > #include <string>
    > #include <algorithm>
    >
    > int main()
    > {
    > std::string str("disprove");
    > std::sort(str.begin(), str.end());
    > std::cout << str << std::endl;
    >
    > }


    Thanks. It's so easy, I just find out :)
     
    Lambda, Sep 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peng Yu
    Replies:
    1
    Views:
    336
    Sarah Thompson
    Jul 12, 2003
  2. Replies:
    14
    Views:
    726
    Jacek Dziedzic
    Apr 6, 2007
  3. Replies:
    10
    Views:
    635
    Torsten Bronger
    Dec 31, 2007
  4. Stef Mientki
    Replies:
    11
    Views:
    10,853
    Martin
    Dec 28, 2008
  5. Sur
    Replies:
    4
    Views:
    226
Loading...

Share This Page