From b45c0d29ee690c8b436a33581d3b108e6064b5a7 Mon Sep 17 00:00:00 2001 From: Oskar Date: Sun, 11 Aug 2024 17:30:28 +0200 Subject: more confusion --- iterator-test-3.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 iterator-test-3.cpp (limited to 'iterator-test-3.cpp') 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 +#include +#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 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; +} -- cgit v1.2.3