CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Posts
    33

    Sorting a string in Alphabetical order

    Can someone help me to a string in Alphabetical order?

  2. #2
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    Ascending sort. Write a compare fxn:
    bool compare(char a, char b)
    {return a < b;}

    Then pass that fxn addess to the STL sort fxn
    char* hello = "Hello";
    int len = strlen(hello);
    sort(hello, hello + len, compare);

    I haven't run this thru compiler so check misspells, etc.

    Steve

  3. #3
    Join Date
    Sep 1999
    Location
    Colorado, USA
    Posts
    1,002
    P.S. Make sure to include the right header file
    #include <algorithm>
    using namespace std;

    Steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured