Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ list of pairs

#include <iostream>
#include <list>
using namespace std;

int main() {
	list<pair<int, char>> pair_list;
  	
  	pair_list.push_front(make_pair(1, 'a'));
    pair_list.push_front(make_pair(2, 'b'));

    pair_list.push_back(make_pair(10, 'x'));
    pair_list.push_back(make_pair(20, 'y'));
  
  	for(auto itr=pair_list.begin();itr!=pair_list.end();itr++) {
    	cout << itr->first << ", " << itr->second << endl;
    }
  
  	return 0;
}

// output
/* 
	2, b
	1, a
	10, x
	20, y
*/
 
PREVIOUS NEXT
Tagged: #list #pairs
ADD COMMENT
Topic
Name
5+1 =