summaryrefslogtreecommitdiff
path: root/4p20.cpp
blob: edc38ce832f2645f353edc00970cd80a48f14919 (plain)
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
#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;
}