Sort string function

closed account (G60iz8AR)
How to do sort string function ? if so please help !
#include <algorithm>
#include<ctime>
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h> // needed for exit() function
using namespace std;

string sortedForm( string word );

int main ( int argc, char **argv)
{
string word;
cout << " Enter a word: ";
cin >> word;
cout << "Forted form of " << word << " is " << sortedForm( word ) << endl;
return 0;

} // END MAIN

string sortedForm( string word )
{
string sortedCopy = word;
sort(sortedCopy.begin(), sortedCopy.end());
return sortedCopy;
}


Just a suggestion: use proper format for your code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <algorithm>
 #include<ctime>
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <stdlib.h> // needed for exit() function
 using namespace std;

 string sortedForm( string word );

 int main ( int argc, char **argv)
 {
 string word;
 cout << " Enter a word: ";
 cin >> word;
 cout << "Forted form of " << word << " is " << sortedForm( word ) << endl;
 return 0;

 } // END MAIN

 string sortedForm( string word )
 {
 string sortedCopy = word;
 sort(sortedCopy.begin(), sortedCopy.end());
 return sortedCopy;
 }
Last edited on
Are you trying to take a single word and put all the letters in alphabetical order?
closed account (G60iz8AR)
@yulingo yes i am
Topic archived. No new replies allowed.