I'm trying to make a c++ program where I can dynamically add points to a list, and then search for if those points are in the list.
I was trying originally to use sets, but am now trying to use vectors. My code below will run, but gets an error involving the search if statement.
#include <stdio.h> /* printf */
#include <bits/stdc++.h> /* vector of strings */
#include <algorithm>
#include <vector>
using namespace std;
void solve_point(vector<vector<char>> &board)
{
printf("solve_point\n");
board[2][2] = 'c';
}
struct point
{
int x;
int y;
};
int main()
{
vector<point> vec;
point point1{4, 1};
point point1{8, 3};
vec.push_back(point1);
if (find(vec.begin(), vec.end(), point1) != vec.end())
{
printf("point1 found in vec\n");
}
else
{
printf("point1 not found in vec\n");
}
}
This leads to some errors saying:
/usr/include/c++/7/bits/predefined_ops.h:241:17: error: no match for ‘operator==’ (operand types are ‘point’ and ‘const point’)
{ return *__it == _M_value; }
..and..
/usr/include/c++/7/bits/predefined_ops.h:241:17: note: ‘point’ is not derived from ‘const __gnu_cxx::new_allocator<_Tp>’
{ return *__it == _M_value; }
I encountered an error similar to this earlier when I was trying to insert a point into a set, is there something wrong with my struct point initialization? Thanks