Files
learning/cpp/Типы данных/hash_table.cpp
2022-05-06 00:49:26 +03:00

35 lines
1.0 KiB
C++
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
int main() {
/*
Синтаксис: unordered_map<тип_ключа, тип_значения> имя;
Методы:
.count(key) - true если существует ключ key, иначе false
.erase(key) - удалить запись с ключом key
.begin() - возвращает итератор к первому элементу
.end() - возвращет итератор точке после последнего элемента
*/
unordered_map<string, string> spnumbers;
spnumbers = { {"one", "uno"}, {"two", "dos"} };
spnumbers["three"] = "tres";
spnumbers["four"] = "cuatro";
cout << "Значение с ключом 'one': ";
cout << spnumbers["one"] << endl;
cout << "Размер таблицы: ";
cout << spnumbers.size() << endl;
// Итерация таблицы:
for (auto i=spnumbers.begin(); i!=spnumbers.end(); i++){
cout << i->first << ":";
cout << i->second << endl;
}
return 0;
}