1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| struct abc {
int a; int b; int c;
abc( int aa, int bb, int cc ) : a(aa), b(bb), c(cc) {}
};
// nécessaire pour les map, pour les hash_table, je ne sais pas
bool operator<(abc const & lhs, abc const & rhs)
{
if (lhs.a != rhs.a) return lhs.a < rhs.a;
else if (lhs.b != rhs.b) return lhs.b < rhs.b;
else return lhs.c < rhs.c;
}
....
typedef std::map< abc, std::string > type_table;
type_table table;
table[abc(1,2,3)] = "un deux trois";
type_table::const_iterator it = table.find(abc(1,2,3));
if (it != table.end())
std::cout << "Trouvé: " << it->second << "\n";
else
std::cout << "Rien trouvé!\n"; |
Partager