C++ -- map、set 、vector 基本操作回顾
map : https://cloud.tencent.com/developer/article/1065697
set: https://cloud.tencent.com/developer/article/1065689
vector : https://cloud.tencent.com/developer/article/1065701
腾讯云系列专栏博客,基本操作清晰明白;
一维和二维动态数组初始化为:
std::vector <int> vec(10,90); //将10个一维动态数组初始为90 std::vector<std::vector<int> > vec(row,vector<int>(col,0)); //初始化row * col二维动态数组,初始化值为0,其实就是每一行初始化为列数个0
获取一维数组长度:
int size = vec.size();
获取二维数组长度:
int size_row = vec.size(); //获取行数 int size_col = vec[0].size(); //获取列数
转自:https://blog.csdn.net/qq_16583687/article/details/75276125
C++ map中key值存在情况判定
count函数
count函数用于统计key值在map中出现的次数,map的key不允许重复,因此如果key存在返回1,不存在返回0
if (testMap.count(key) == 0) cout << "no this key" << endl;
find函数
如果key存在,则find返回key对应的迭代器,如果key不存在,则find返回尾后迭代器 .end()
例:
if (testMap.find(key) == testMap.end()) cout << "no this key" << endl;