Simple string manipulation in C++

The code bellow is a simple example, howto pass string to a function.


#include
#include
using namespace std;
void display(string a, string b, string comp){
cout << "The word \""<< a << "\" is " << comp << " the word \"" << b << "\"" << endl;
}
int main(int argc,char **argv){
if(argc < 3){
cout << "Please type two words after the program name." << endl;
}else{
string a = argv[1];
string b = argv[2];
if(a < b){
display(a,b,"less than");
}else if(a > b){
display(a,b,"greater than");
}else if(a == b){
display(a,b,"equal to");
}
}
return 0;
}

  • Share/Bookmark

Post a Comment

Your email is never shared. Required fields are marked *

*
*