i trying iterate through set of strings, declared here:
std::set<std::string>ab;, , here std::set<int>::iterator iter;
the problem here:
for(iter = ab.begin(); iter != ab.end(); ++iter) { std::cout << *iter << n; in theory, should print out contents of ab (available buildings), instead, gives 2 errors:
error: no viable overloaded '=' -> [ for(iter = ab.begin(); ]
and
error: invalid operands binary expression -> [ std::set< int >::iterator ]
any appreciated, thanks.
instead of
std::set<int>::iterator iter; use
std::set<std::string>::iterator iter; since using c++11, can use:
for(auto iter = ab.begin(); iter != ab.end(); ++iter) { std::cout << *iter << n; better yet, use range construct:
for(auto const& item : ab) { std::cout << item << n;
Comments
Post a Comment