-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path16.12.cpp
51 lines (43 loc) · 1.32 KB
/
16.12.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
#include "Blob.h"
#include <string>
#include <vector>
#include <iostream>
using StrBlob = Blob<std::string>;
using StrBlobPtr = std::vector<std::string>::iterator;
using ConstStrBlobPtr = std::vector<std::string>::const_iterator;
using std::string;
using std::cout;
using std::endl;
using std::cin;
using std::vector;
int main() {
// StrBlob is an alias to Blob<string>
StrBlob sb{"a", "b", "c", "d", "e", "f", "g", "h"};
for (ConstStrBlobPtr p = sb.cbegin(); p != sb.cend(); cout << *p++ << " ") ; // Printing with iterators
cout << endl;
for (StrBlob::size_type i = 0; i != sb.size(); ++i) { // Printing via subscription
cout << sb[i] << " ";
}
cout << endl;
// Reading integers into the back of a Blob<int>, then printing them from the Blob instance
Blob<int> ib;
for (int i; cin >> i; ib.push_back(i)) ; // Reading
for (vector<int>::const_iterator p = ib.cbegin(); p != ib.cend(); cout << *p++ << " " ) ; // Printing
cout << endl;
Blob<int> ib2{1,2,3,4,5,6,7,8};
if (ib == ib2) {
cout << "ib and ib2 are equal" << endl;
} else if (ib != ib2) {
cout << "ib and ib2 are not equal" << endl;
}
while (!ib2.empty()) {
cout << ib2.front() << " ... " << ib2.back() << endl;
ib2.pop_back();
}
for (vector<int>::iterator p = ib.begin(); p < ib.end(); ++p) {
*p *= 2;
cout << *p << " ";
}
cout << endl;
return 0;
}