I'm just learning programming in c++. In my homework I need to compare three strings given by the user by a prompt. I know that for a function to modify certain values directly instead of returning a value I need to use pointers. I also know that strings already behave like pointers. This is my code so far but I don't know where I'm wrong:
#include"std_lib_facilities.h"
void switching (string x, string y){
string flag;
if (x>y){flag=y;
y=x;
x=flag;
}
}
int main(){
string s1, s2, s3;
cout<<"introduce three words: ";
cin>>s1>>s2>>s3;
switching(s1,s2);
cout<<s1<<" "<<s2<<" "<<s3;
cout<<endl;
switching(s2,s3);
cout<<s1<<" "<<s2<<" "<<s3;
cout<<endl;
switching(s1,s2);
cout<<s1<<" "<<s2<<" "<<s3;
cout<<endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire