【STL】-Map/Multimap的用法

初始化:

map<string,double> salaries;

算法:

1. 赋值。salaries[ "Pat" ] = 75000.00;

2. 无效的索引将自动添加一项

cout << salaries[ "Jan" ] << endl;

3. Map的第一个或者第二个元素为数组的情况

代码:

 #include <map>
#include <string>
#include <iostream>
using namespace std; int main( )
{
map<string,double> salaries; salaries[ "Pat" ] = 75000.00;
cout << salaries[ "Pat" ] << endl;
cout << salaries[ "Jan" ] << endl; map<string,double>::const_iterator itr;
itr = salaries.find( "Jan" );
if( itr == salaries.end( ) )
cout << "Not an employee of this company!" << endl;
else
cout << itr->second << endl; return ;
}

输出:

$ ./a.exe
上一篇:A Statistical View of Deep Learning (I): Recursive GLMs


下一篇:在 Oracle 中使用正则表达式