c++ std pair code example
Example 1: pair c++
#include <utility>
#include <iostream>
int main () {
std::pair <int,int> foo;
std::pair <int,int> bar;
foo = std::make_pair (10,20);
bar = std::make_pair (10.5,'A');
std::cout << "foo: " << foo.first << ", " << foo.second << '\n';
std::cout << "bar: " << bar.first << ", " << bar.second << '\n';
return 0;
}
Example 2: std pair example
#include <utility>
#include <string>
#include <iostream>
int main () {
std::pair <std::string,double> product1;
std::pair <std::string,double> product2 ("tomatoes",2.30);
std::pair <std::string,double> product3 (product2);
product1 = std::make_pair(std::string("lightbulbs"),0.99);
product2.first = "shoes";
product2.second = 39.90;
std::cout << "The price of " << product1.first << " is $" << product1.second << '\n';
std::cout << "The price of " << product2.first << " is $" << product2.second << '\n';
std::cout << "The price of " << product3.first << " is $" << product3.second << '\n';
return 0;
}