What is the error in this code:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct symtab{
string name;
string location;
};
vector<symtab> symtab_details;
bool search_symtab(string s){
if (find (symtab_details.begin(), symtab_details.end(), s)!=symtab_details.end()) return true;
return false;
}
int main() {
bool get = search_symtab("ADD");
return 0;
}
I am getting the following error:
usr/include/c++/4.8.2/bits/stl_algo.h:166:17: error: no match for ‘operator==’ (operand types are ‘symtab’ and ‘const std::basic_string’) if (*__first == __val)
findfunction tries to find asymtabstructure in your vector. Learn about lambda expressions andstd::find_iffor one way of solving your problem.