iterator problem with vectors

closed account (E3h7X9L8)
so I want to write every element in the vector till it reaches an empty element(which is 0) using iterators , when i try to compile the program i have those two errors:

1.'empty' : is not a member of 'std::_Vector_const_iterator<std::_Vector_val<std::_Simple_types<int>>>'

2.invalid return type 'const int *' for overloaded 'operator ->'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <vector>
using namespace std;

int main()

{
	vector<int> test{ 1, 2, 3, 0, 4, 0, 0, 5 };
	for (auto it = test.cbegin();
		it != test.cend() && !it->empty(); ++it)
		cout << *it << endl;

	cin.ignore(2, ' ');
}
closed account (SECMoG1T)
replace this !it->empty() with this (*it!=0) note: ints have no member called empty().
closed account (E3h7X9L8)
oh so that was the catch thank you :)
Topic archived. No new replies allowed.