-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_string.cpp
More file actions
52 lines (39 loc) · 915 Bytes
/
1_string.cpp
File metadata and controls
52 lines (39 loc) · 915 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
46
47
48
49
50
51
52
#include <iostream>
using namespace std;
int main()
{
string s1 = "Hi there!";
string s2 = " What's up";
string s3 = "abcde";
string s = s1 + s2;
cout << s; // Hi there! What's up
cout << s.size(); // 19
cout << s[0]; // H
// go second assci value
for (int i = 0; i < s.size(); i++)
{
s[i] = s[i] + 1;
}
cout << s; // Ij!uifsf"!Xibu(t!vq
// delete last char
s1.pop_back();
cout << s1; // Hi there
// delete first item
s3.erase(s3.begin() + 0);
cout << s3; // bcde
// take sting as input without space
string x;
cin >> x;
cout << x; // abc
// take sting as input without space
string y;
getline(cin, y);
cout << y; // abc def
// remove first and last char from input
string z;
cin >> z; // abcde
z.erase(z.begin());
z.pop_back();
cout << z; // bcd
return 0;
}