-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlength of a string.cpp
More file actions
45 lines (33 loc) · 854 Bytes
/
length of a string.cpp
File metadata and controls
45 lines (33 loc) · 854 Bytes
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
// Program to find the length of a string using a loop
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
string s = "Change the mode";
int size = 0;
for(int i = 0; s[i] != '\0'; i++)
{
size++;
}
cout << "Size :- " << size << endl;
return 0;
}
// Program to find the string length using inbuilt methods
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
string s = "Change the mode";
cout << "Size using size() :- " << s.size() << endl;
cout << "Size using length() :- " << s.length() << endl;
return 0;
}
// Program to find the length of a string using cstr()_ method using strlen function
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
string s = "Change the mode";
cout << "Size :- " << strlen(s.c_str()) << endl;
return 0;
}