error C2678: binary '[': no operator found which takes a left-hand operand of type 'const std::map<Cell,std::string,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>
// Example program
#include <iostream>
#include <string>
#include <map>
using std::map;
using std::string;
enumclass Cell {
closed,
open,
flagged
};
const map<Cell, string> cellToSymbol = {
{Cell::closed, ""},
{Cell::open, ""},
{Cell::flagged, "@<"}
};
void lag()
{
string s = cellToSymbol.find(Cell::closed)->second;
// If you can't be logically sure that the key is in the map,
// check to make sure the result does not equal map.end()
auto it = cellToSymbol.find(Cell::flagged);
if (it != cellToSymbol.end())
{
std::cout << "found\n";
}
else
{
std::cout << "not found\n";
}
}
int main()
{
lag();
}