-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ex14_18_StringMain.cpp
64 lines (53 loc) · 1.07 KB
/
ex14_18_StringMain.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
64
#include "ex14_18_String.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
void foo(String x)
{
std::cout << x << std::endl;
}
void bar(const String& x)
{
std::cout << x.c_str() << std::endl;
}
String baz()
{
String ret("world");
return ret;
}
int main()
{
char text[] = "world";
String s0;
String s1("hello");
String s2(std::move(s0));
String s3 = s1;
String s4(text);
s2 = s1;
if (s2 == s1)
std::cout << "s2 == s1" << std::endl;
foo(s1);
bar(s1);
foo("temporary");
bar("temporary");
String s5 = baz();
std::vector<String> svec;
//svec.push_back(s0);
svec.push_back(s1);
svec.push_back(s2);
svec.push_back(s3);
svec.push_back(s4);
svec.push_back(baz());
svec.push_back("good job");
for (const auto &s : svec) {
std::cout << s << std::endl;
}
std::cout << "Input a string: ";
String s6;
std::cin >> s6;
std::cout << s6 << std::endl;
if (s6 > s1)
std::cout << "s6 > s1" << std::endl;
}