-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOtherUsefulFunction.cpp
More file actions
82 lines (63 loc) · 2.33 KB
/
OtherUsefulFunction.cpp
File metadata and controls
82 lines (63 loc) · 2.33 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* \file OtherUsefulFunction.cpp
* \brief
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::string str("GeeksforGeeks");
std::string str1("GeeksforGeeks");
// Comparing strings using compare()
if (str.compare(str1) == 0)
std::cout << "Strings are equal";
else
std::cout << "Strings are unequal";
std::string str2("The Geeks for Geeks");
// find() returns position to first
// occurrence of substring "Geeks"
// Prints 4
std::cout << "First occurrence of \"Geeks\" starts from : ";
std::cout << str2.find("Geeks") << std::endl;
// Prints position of first occurrence of
// any character of "reef" (Prints 2)
std::cout << "First occurrence of character from \"reef\" is at : ";
std::cout << str2.find_first_of("reef") << std::endl;
// Prints position of last occurrence of
// any character of "reef" (Prints 16)
std::cout << "Last occurrence of character from \"reef\" is at : ";
std::cout << str2.find_last_of("reef") << std::endl;
// rfind() returns position to last
// occurrence of substring "Geeks"
// Prints 14
std::cout << "Last occurrence of \"Geeks\" starts from : ";
std::cout << str2.rfind("Geeks") << std::endl;
std::string str3("Geeksfor");
// Printing the original string
std::cout << str3 << std::endl;
// Inserting "for" at 5th position
str3.insert(8,"Geeks");
// Printing the modified string
// Prints "GeeksforGeeks"
std::cout << str3 << std::endl;
//Clearing the string
str3.clear();
//Checking if string is empty. Returns a boolean value.
if (str3.empty() ==true) //This also works. str3.empty()==1
std::cout << "The string is Empty" << std::endl;
else
std::cout <<"The string is not empty." << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
Strings are equalFirst occurrence of "Geeks" starts from : 4
First occurrence of character from "reef" is at : 2
Last occurrence of character from "reef" is at : 16
Last occurrence of "Geeks" starts from : 14
Geeksfor
GeeksforGeeks
The string is Empty
#endif