I'm trying to compare values from two different vectors--if they are the same, a number is incremented, to count the similarities.
There's a four-element int vector with random user input (e.g. 8 9 0 7)
and a ten-element int vector containing 0-9 (i.e. 0 1 2 3 4 5 6 7 8 9).
I tried comparing them with something like this:
vector<int>input;
vector<int>integers;
int total_hits = 0;
for (int i=0; i < 4; ++i){
for (int j=0; j < 10; ++j)
if (input[i] == integers[j])
++total_hits;
I get the error: pointer to a function used in arithmetic (in regards to input[i] == integers[j]), and another saying that C++ forbids comparison between pointer and integer (regarding the same line).
Is there any way to compare two vector elements??????
But the problem is that the compiler won't allow me to do
if (input[i] == integers[j]), saying that I'm using a pointer to a function in arithmetic and that I can't compare a pointer and an integer. I think it's saying that input[i] is a pointer to a function and integers[j] is an integer, even though both should be integers.
vector<int> input();
vector<int> integers(range_top);
int zero = 0;
int total_hits = 0;
for (int i=0; i < range_top; ++i){ // put values into integer vector
integers.push_back(i);
}
for (int i=0; i < num_slots; ++i){ // count similarities in vectors
for (int j=0; j < range_top; ++j)
if (input[i] == integers[j])
++total_hits
}
And these are the errors I get:
proj3.cc:210:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
if (input[i] == integers[j])
^
proj3.cc:210:34: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (input[i] == integers[j])
^