-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_DSString.cpp
More file actions
66 lines (49 loc) · 1.96 KB
/
Copy pathtest_DSString.cpp
File metadata and controls
66 lines (49 loc) · 1.96 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
#include "DSString.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main() {
DSString myString = "Hello, World!";
cout << myString << endl;
// this uses the one argument constructor in DSString and then the inherited operator=
myString = "Good bye!";
cout << myString << endl;
cout << "substr: " << myString.substring(5, 3) << endl;
DSString a = "test";
DSString b = a;
cout << boolalpha;
cout << (a == b) << endl;
// use initialization list (see DSVector.h)
vector<DSString> strings
= { DSString("bbb"), DSString("aaa"), DSString("ddd"), DSString("eee"), DSString("ccc") };
// find strings
for (const auto& s : strings)
cout << s << "\n";
cout << "found ddd: " << (find(strings.begin(), strings.end(), DSString("ddd")) != strings.end()) << endl;
cout << "found zzz: " << (find(strings.begin(), strings.end(), DSString("zzz")) != strings.end()) << endl;
// sorting
sort(strings.begin(), strings.end());
for (const auto& s : strings)
cout << s << "\n";
// now we can do more efficient search
cout << "found ddd: " << binary_search(strings.begin(), strings.end(), DSString("ddd")) << endl;
cout << "found zzz: " << binary_search(strings.begin(), strings.end(), DSString("zzz")) << endl;
stringstream ss("Test Streams");
DSString inputdString, inputdString2;
ss >> inputdString >> inputdString2;
cout << inputdString << '\n' << inputdString2 << endl;
stringstream ss2("Test Stream with spaces using getline");
DSString inputString3;
getline(ss2, inputString3);
cout << inputString3 << endl;
stringstream ss3("Test Stream with spaces using getline and delimiter;abcdefg");
DSString inputString4;
getline(ss3, inputString4, ';');
cout << inputString4 << endl;
DSString removeChar = "Hello: World";
removeChar.remove(5);
cout << removeChar << endl;
return 0;
}