Error: no match for operator=

On the program below I get get this error when compling:

20 11 C:\Dev-Cpp\MAlikChapter13\Example13-11.cpp [Error] no match for 'operator=' (operand types are 'std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}' and 'int*')

I get this error on there two lines:
1
2
        location = find_end(list1, list1 + 10, list2, list2 + 2);
	location = find_first_of(list1, list1 + 10, list3, list3 + 5);

HEre is the complete program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cctype>

using namespace std;

int main() {
	
	int list1[10] = {12, 34, 56, 21, 34, 78, 34, 56, 12, 25};
	int list2[2] = {34, 56};
	int list3[5] = {33, 48, 21, 34, 73};
	
	vector<int>::iterator location;
		ostream_iterator<int> screen(cout, " ");
		
	location = find_end(list1, list1 + 10, list2, list2 + 2);
	location = find_first_of(list1, list1 + 10, list3, list3 + 5);
	
		copy(list1.begin(), list1.end(), screen);              
	cout<<endl;
		cout<< endl << *location;
}
find_end is a templated function. What it returns depends on the input parameters you give it. In your case, it will return an int*.

You've got a vector<int>::iterator object (location), and you're trying to assign an int* to it.

You can't assign an int* to an object of type vector<int>::iterator.

copy(list1.begin(), list1.end(), screen);
This will not work. list1 is an object of type int[10]. Such an object does not have a class function begin.

I recommend you stop using arrays and start using vectors. You clearly want to use vector functions like begin, and you clearly want to use vector iterators. So don't use int arrays. Use vector<int>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>

using namespace std;

int main() {
	
	int list1[10] = {12, 34, 56, 21, 34, 78, 34, 56, 12, 25};
	int list2[2] = {34, 56};
	int list3[5] = {33, 48, 21, 34, 73};
	
	int *location;
	ostream_iterator<int> screen(cout, " ");
		
	location = find_end(list1, list1 + 10, list2, list2 + 2);
	copy(list1, list1 + 10, screen);              
	cout <<"\n" << *location <<"\n\n";
		
	location = find_first_of(list1, list1 + 10, list3, list3 + 5);
	copy(list1, list1 + 10, screen);              
	cout <<"\n" << *location <<"\n\n";
}


Not sure what you actually intended as output.
Thank you all. That problem error of (operator=) have disappeared. And got the output that the textbook said I will get with both functions: find_end "and" find_first.
Topic archived. No new replies allowed.