-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.cpp
More file actions
80 lines (66 loc) · 2.25 KB
/
String.cpp
File metadata and controls
80 lines (66 loc) · 2.25 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
#include <bits/stdc++.h>
using namespace std;
void solve() {
// --- Initialization ---
string s1(4, 'a'),
s2 = "abcdefghij";
// assign(n, char)
// --- Iterators ---
// begin(), end()
// rbegin(), rend()
// --- Capacity ---
// size(), empty()
// reserve(n), capacity()
// --- Element accessa ---
// front(), back()
// [index], at(index)
// --- Modifiers ---
// push_back(char), += char, += string
// append(n, char), append(string)
// insert(pos, char), insert(pos, n, char), insert(pos, initializer_list)
// insert(pos, it_first, it_last)
// insert(index, n, char), insert(index, string), insert(index, initializer_list)
// pop_back()
// erase(pos), erase(pos_first, pos_last), erase(index, length)
// replace(pos_first, pos_last, n, char), replace(pos_first, pos_last, string)
// replace(index, length, n, char), replace(index, length, string)
// replace(pos_first, pos_last, it_first, it_last)
// resize(n, char), clear()
// --- Search ---
// Return index of first & last occurrence of a string (string::npos if not found)
// s.find(string, start_index=0), s.rfind(string, start_index=npos)
cout << s1.find("aa") << ' ' << s1.rfind("aa") << '\n';
// --- Operations ---
// contains(string)
// starts_with(string), ends_with(string)
// substr(index, length)
// --- Numeric conversions ---
// stoi(string), stol(string), stoll(string)
// stoul(string), stoull(string)
// stof(string), stod(string), stold(string)
// to_string(number)
int n1 = stoi("1234");
int n2 = stoi("10010", nullptr, 2);
cout << n1 << ' ' << n2 << '\n';
string s_int = to_string(1111);
string s_float = to_string(2222.22);
cout << s_int << ' ' << s_float << '\n';
// --- Hints ---
// assign replacing a string with new properties (size and elements).
// resize holding old data and expanding the new string with new elements.
// reserve change capacity of string.
// getline(cin, s)
for (auto ch : s1) {
cout << ch << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
return 0;
}