C++Primer第五版 练习11.24(解答)

来源:互联网 发布:ubuntu 休眠设置 编辑:程序博客网 时间:2024/06/16 20:13

练习11.24:下面的程序完成什么功能?

map<int,int> m;m[0] = 1;

答:找到关键字为0的元素,将其mapped_value赋值为1

/**2015/10/10*C++Primer第五版*11.3.4节练习 *练习11.24*问题描述:练习11.24:下面的程序完成什么功能?map<int,int> m;m[0] = 1;*说明: 将关键字为0的这个元素,值5变成1*作者:Nick Feng*邮箱:nickgreen23@163.com */ #include <iostream>#include <vector>#include <map>using namespace std;int main(){    map<int,int> m1 = {{0,5},{1,1},{2,2},{3,3}};    for(auto &m : m1)    cout << m.first << " " << m.second << "...";    cout << endl;      m1[0] = 1;//将关键字为0的这个元素,值5变成1      for(auto &m : m1)    cout << m.first << " " << m.second << "...";    cout << endl;    return 0; } 
0 0
原创粉丝点击