summaryrefslogtreecommitdiff
path: root/iterator-test-3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'iterator-test-3.cpp')
-rw-r--r--iterator-test-3.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/iterator-test-3.cpp b/iterator-test-3.cpp
new file mode 100644
index 0000000..09cf159
--- /dev/null
+++ b/iterator-test-3.cpp
@@ -0,0 +1,34 @@
+#include <iostream>
+#include <vector>
+#include "sales_data.hpp"
+#include "sales_item.hpp"
+/*
+ *
+ * Pretty much same as last iterator test
+ * Still a bit confused about this stuff.
+ * Especially the fact that you cant add two iterators
+ */
+
+using std::string;
+using std::cout;
+using std::cin;
+using std::cerr;
+using std::clog;
+using std::endl;
+using std::vector;
+int main () {
+
+
+ vector<int> vec = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
+ auto it1 = vec.begin(); // points at 10 in the vector
+ it1 += 9; // we go 9 places forwards - 20 - 30 - 40 - 50 - 60 - 70 - 80 - 90 - 100.
+ // it1 now points to 100
+ cout << *it1 << endl;
+ auto it2 = vec.begin();
+ auto diff = it1 - it2;
+ auto it3 = vec.begin();
+ it3 += diff;
+ cout << diff << " < diff" << endl;
+ cout << *it3 << endl;
+ return 0;
+}