use_pair

来源:互联网 发布:阿里云pc 编辑:程序博客网 时间:2024/06/07 02:08
//pair常见的使用方式#include<iostream>#include <utility>#include <string>#include <tuple>using namespace std;int main(){    pair<string,double> product1;    pair<string,double> product2("tomatoes",2.30);;    pair<string,double> product3(product2);    product1 = make_pair(string("lightbulbs"),0.99);    product2.first = "Shoes";    product2.second = 39.09;    cout << product1.first << " " << product1.second << endl;    cout << product2.first << " " << product2.second << endl;    cout << product3.first << " " << product3.second << endl;    pair<string,int> planet,homeplanet;    planet = make_pair("Earth",6371);    homeplanet = planet;    cout << "Home Planet: " << homeplanet.first << endl;    cout << "Planet size: " << homeplanet.second << endl;    planet.swap(homeplanet);    cout << "Planet Planet: " << planet.first << endl;    cout << "Planet size: " << planet.second << endl;    pair<int,char> foo(10,'x');    get<0>(foo) = 50;    cout << "foo contains ";    cout << get<0>(foo) << " and " << get<1>(foo) << endl;    tuple<int,char> mytuple(10,'a');    get<0>(mytuple) = 20;    cout << "mytuple contains: ";    cout << get<0>(mytuple) << " and " << get<1>(mytuple) << endl;    cout << endl;    return 0;}
原创粉丝点击