Comparing Strings [example]

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 <iostream>
#include <string>
using namespace std;
int main() 

{
string firststring;
string secondstring;

cout<<"Enter first string:";
cin>>firststring;
cout<<endl;
cout<<"Enter second string:";
cin>>secondstring;
cout<<endl<<endl;

int value = firststring.compare(secondstring);

cout<<"With firststring as comapre function's object,"<<endl;
cout<<"and secondstring as its argument, compare" <<endl; 
cout<<"returns a value of "<< value; 

char f;
cin>>f;
return 0;
}
Last edited on
Your question is?

Btw: You can also use == for string comparisons.
Last edited on
Topic archived. No new replies allowed.