Jul 11, 2010 at 8:10pm UTC
Hi guys, im having trouble with my code. Im trying to search within the vector for the int checker. The error Im getting is
error C3892: 'iter' : you cannot assign to a variable that is const
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int numbers=10, element, checker;
vector<int> group;
int count = 0;
vector<int>:: const_iterator iter;
while (count != numbers)
{
count++;
cout << "Enter numbers: ";
cin >> element;
group.push_back(element);
}
cout << "Please enter a number to search for within the array: ";
cin >> checker;
for (iter = group.begin(); iter != group.end(); ++iter)
if (*iter = checker)
cout << "Your number is in the array";
else
cout << "Your number is not in the array";
system("pause");
return 0;
}
Jul 11, 2010 at 8:40pm UTC
The equality operator is ==.
Note that there is std::find.
count is redundant, the vector already keeps track of its size:
while (group.size()<numbers)
Jul 12, 2010 at 5:58pm UTC
thanks for your help! I needed to use the equality operator, also changed my code a bit. Thank you.