Sorting Characters Of A C++ String

前端 未结 4 1207
说谎
说谎 2020-12-22 23:19

If i have a string is there a built in function to sort the characters or would I have to write my own?

for example:

string word = \"dabc\";
<         


        
4条回答
  •  无人及你
    2020-12-22 23:56

    You can use sort() function. sort() exists in algorithm header file

            #include
            using namespace std;
    
    
            int main()
            {
                ios::sync_with_stdio(false);
                string str = "sharlock";
    
                sort(str.begin(), str.end());
                cout<

    Output:

    achklors

提交回复
热议问题