summaryrefslogtreecommitdiff
path: root/4p20.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-20 13:51:53 +0200
committerOskar <[email protected]>2024-08-20 13:51:53 +0200
commit12dda8d5244e86096a5ea56014073dd1892cc409 (patch)
treeffaf835edd33da23a58405db5e733ebfc71e5a5e /4p20.cpp
parentd0c6ac2b68380020d76d7f938307e056a25eb5f5 (diff)
more
Diffstat (limited to '4p20.cpp')
-rw-r--r--4p20.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/4p20.cpp b/4p20.cpp
new file mode 100644
index 0000000..edc38ce
--- /dev/null
+++ b/4p20.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+#include <iterator>
+#include <vector>
+
+/*
+ *
+ * 4.20
+ *
+ *
+ */
+
+int main () {
+
+ std::string s1 = "Wow!";
+ std::string s2 = "C++ is very cool, i like it!";
+ std::string s3 = "I also really like C!";
+ std::vector<std::string> vs;
+ vs.push_back(s1);
+ vs.push_back(s2);
+ vs.push_back(s3);
+ std::vector<std::string>::iterator iter = vs.begin();
+ std::cout << *iter++ << std::endl;
+ std::cout << iter->empty() << std::endl;
+ std::cout << iter++->empty() << std::endl;
+ /*
+ (a) *iter++; // valid
+ (b) (*iter)++; // not valid? we dereference and try to increment a string which does not work
+ (c) *iter.empty() // not valid, we try to call .empty() member function on an iterator, which does not exist
+ (d) iter->empty(); // valid
+ (e) ++*iter; // not valid, we are dereferencing and then trying to increment a string. I am a bit confused because i thought precedence of the ++ operator would make it increment first and then dereference it but it does not seem so...
+ (f) iter++->empty(); // valid
+ */
+
+ return 0;
+}