-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind the largest string.cpp
More file actions
46 lines (37 loc) · 1.07 KB
/
find the largest string.cpp
File metadata and controls
46 lines (37 loc) · 1.07 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Program to find the largest string
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string s1, s2;
cout << "Enter the first string:- \n" << endl;
getline(cin, s1);
cout << "Enter the second string:- \n" << endl;
getline(cin, s2);
if(strlen(s1.c_str()) == strlen(s2.c_str()))
{
cout << "Both the strings are equal" << endl;
}
else if(strlen(s1.c_str()) > strlen(s2.c_str()))
{
cout << "The first string is larger than second string" << endl;
}
else
{
cout << "The second string is greater than first string" << endl;
}
return 0;
}
/* Explanation:-
To find out the larger string, you need to find out its length.
In C++, we can find out the length of a string using the strlen method.
strlen() in C++:-
strlen() is used to find out the length of a string.
It is defined in cstring header file.
cstring is used for c-style null-terminated byte string.
It includes a lot of useful string methods and strlen() is one among them.
syntax:-
size_t strlen( const char* str );
It takes one C style string as its argument and returns its size.
*/