Enter three strings and sort them alphabetically in the of sample code

  • 2020-04-02 01:57:18
  • OfStack

Define a string variable using the string method

Implementation code:


#include<iostream>
#include<string>
using namespace std;
int main(){
 string a,b,c,t;
 cout<<"please input first string:"<<endl;
 cin>>a;
 cout<<"please input second string:"<<endl;
 cin>>b;
 cout<<"please input third string:"<<endl;
 cin>>c;
 if(a>b){
  t=a;
  a=b;
  b=t;
 }
 if(a>c){
  t=a;
  a=c;
  c=t;
 }
 if(b>c){
  t=b;
  b=c;
  c=t;
 }
 cout<<a<<"<<"<<b<<"<<"<<c<<endl;    
 return 0; 
}


Related articles: