-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps.cpp
More file actions
37 lines (27 loc) · 825 Bytes
/
maps.cpp
File metadata and controls
37 lines (27 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Example of using key-value pairs (std::maps) in C++.
*/
#include <string>
#include <map>
#include <iostream>
using namespace std;
void initMap(std::map<string, int> &temp_map) {
temp_map["CG"]=0;
temp_map["CA"]=0;
};
//#define TEST_MODE 1
/* ***************************************************************************
Main function
*************************************************************************** */
int main (int argc, char* argv[]) {
std::map<string, int> totM; // declare
initMap(totM); // initialize
string ctxt="CG";
totM[ctxt]++; // add to total
typedef map<string, int>::const_iterator MapIterator;
for (MapIterator iter = totM.begin(); iter != totM.end(); iter++)
{
cout << iter->first << " -> " << iter->second << endl;
}
// print map.
}