[ create a new paste ] login | about

Link: http://codepad.org/9mCzCxq8    [ raw code | output | fork ]

C++, pasted on Nov 21:
#include <iostream>
#include <utility>
#include <iomanip>
#include <map>

using namespace std;
typedef pair<int, int> Key; //pair

void display (map <Key,float> &m) // to print maps
{
    cout << "\tTotal size: " << m.size() << endl; 
    map <Key,float>::iterator it;
    for (it = m.begin(); it != m.end(); ++it)
       cout << setw(10) << it->first << setw(5) << it->second << endl;

    cout << endl; 
}

int main() {

map< Key , float> mapa; //create map

Key p1 (1, 45); //key values
Key p2 (2, 20);

mapa[p1]= 25.11; //map float to keys
mapa[p2]= 11.23;

display(mapa); //display map

return 0;

}


Output:
1
2
3
4
	Total size: 2
         (1, 45)25.11
         (2, 20)11.23



Create a new paste based on this one


Comments: