Lets look at the example now:
//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
//A simple example of C++ STL container 'pair'
#include<iostream>
#include<string>
#include<utility>
using namespace std;
int main()
{
pair<string, string> name("Zahid","Ghadialy"); //firstname, lastname
string custName = name.first+" "+name.second;
pair<string, int> customerNum(custName, 23456); //firstname, cust. no.
pair<int, int> customerAge(customerNum.second, 30); //cust. no., age
cout<<"Customer Full Name = "<<custName<<endl;
cout<<"Customer Number of "<<customerNum.first<<" is "<<customerNum.second<<endl;
cout<<"Age of Customer Number = "<<customerAge.first<<" is "<<customerAge.second<<endl;
//If we now want to increment say, age by 1
customerAge.second++;
cout<<"New age of Customer Number = "<<customerAge.first<<" is "<<customerAge.second<<endl;
return 0;
}
No comments:
Post a Comment