Get errors in C using vector and struct
•
Java
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 received the following error:
Solution
You are trying to find STD:: string, "add" in STD:: vector < symtab > Of course not
What you need is STD:: find_ if.
auto it = std::find_if(symtab_details.begin(),[&s](symtab const& item) { return item.name == s; }); return (it != symtab_details.end());
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码