diff options
author | Oskar <[email protected]> | 2024-08-11 17:30:28 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-11 17:30:28 +0200 |
commit | b45c0d29ee690c8b436a33581d3b108e6064b5a7 (patch) | |
tree | 90b0df74cb9be982d35b3287f105c2e67f117ebb /iterator-test-3.cpp | |
parent | c6a3ec820eeb105752b833c9f5e44f0244a41c6d (diff) |
more confusion
Diffstat (limited to 'iterator-test-3.cpp')
-rw-r--r-- | iterator-test-3.cpp | 34 |
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; +} |