-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvid31.cpp
63 lines (52 loc) · 1.2 KB
/
vid31.cpp
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
#include <iostream>
#include <string>
using namespace std;
int main()
{ // Declaration of String
string str;
str = "Divyansh Mittal";
string str1(5, 'D');
// String Input
string str2;
getline(cin, str2);
// Append two Strings
string s1 = "fam", s2 = "ily";
s1.append(s2);
cout << s1 + s2 << endl;
// To clear a string
str.clear();
// To compare two strings
string s3 = "abc";
string s4 = "xyz";
cout << s4.compare(s3) << endl;
// Empty Function
s3.clear();
if (s3.empty())
{
cout << "String is empty." << endl;
}
if (!s4.empty())
{
cout << "String is not empty." << endl;
}
// To erase a string
str.erase(8, 7);
cout << str << endl;
// Find Function
cout << str.find("ivy") << endl; // Returns index
// Insert function
str.insert(0, "The");
cout << str << endl;
// Length of the String
cout << str.length() << endl;
cout << str.size() << endl;
// Sub-String
string l = str.substr(9);
cout << l << endl;
// String to int
string f = "786";
int x = stoi(f);
cout << x << endl;
cout << to_string(x) + "2" << endl;
return 0;
}