using sort in C++ to sort a string starting from 2nd character to last character

I want to sort a string starting from 2nd character to last character.Currently i am able to sort the string as per my requirement but i want to utilize sort function in C++ to acheive the same

Sample input :-san test van best

Sample output:-san van test best

My current program

for (int i1 = 0; i1 < n; ++i1) {
    for (int j1 = i1 + 1; j1 < n; ++j1) {
        temp5 = arr[j1].substr(1, arr[j1].length() - 1);
        temp6 = arr[i1].substr(1, arr[i1].length() - 1);
        if (temp6.compare(temp5) > temp5.compare(temp6)) {
            a = arr[i1];
            arr[i1] = arr[j1];
            arr[j1] = a;
        }
    }
}


Read more here: https://stackoverflow.com/questions/66274314/using-sort-in-c-to-sort-a-string-starting-from-2nd-character-to-last-character

Content Attribution

This content was originally published by psaraj12 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: