-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathString_Stl.cpp
More file actions
81 lines (81 loc) · 2.33 KB
/
String_Stl.cpp
File metadata and controls
81 lines (81 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
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
int choice, pos, len;
string::iterator it;
size_t found;
string s, str = "This is a Test String.";
cout<<"Initial String is--> "<<str<<endl;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"String Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Substring in a String"<<endl;
cout<<"2.Erase Substring from a String"<<endl;
cout<<"3.Append Substring to a String"<<endl;
cout<<"4.Replace the String with a Substrng"<<endl;
cout<<"5.Size of the String"<<endl;
cout<<"6.Find substring in a String"<<endl;
cout<<"7.Display the String"<<endl;
cout<<"8.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter the substring to be inserted: ";
cin>>s;
cout<<"Position after which substring to be inserted: ";
cin>>pos;
if (pos <= str.length())
str.insert(pos, s);
else
cout<<"Position out of bounds"<<endl;
break;
case 2:
cout<<"Position after which substring to be erased: ";
cin>>pos;
cout<<"Length of the substring to be deleted: ";
cin>>len;
str.erase(pos, len);
break;
case 3:
s = " This is an appended string.";
str.append(s);
break;
case 4:
s = "n example";
str.replace(9, 5, s);
break;
case 5:
cout<<"Size of the string: "<<str.size()<<endl;
break;
case 6:
cout<<"Enter substring to be found: ";
cin>>s;
found = str.find(s);
if (found != string::npos)
cout <<"Substring "<<s<<" found at " << found <<endl;
else
cout <<"Substring "<<s<<" not found"<<endl;
break;
case 7:
for (it = str.begin(); it != str.end(); ++it)
{
cout<<*it;
}
cout<<endl;
break;
case 8:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}