This C++ Program demonstrates implementation of Pairs in STL.
Here is source code of the C++ Program to demonstrate Pairs in STL. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Implement Pairs in Stl
*/
#include <iostream>
#include <utility>
#include <string>
#include <cstdlib>
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.90;
cout<<"The price of "<<product1.first<<" is $"<<product1.second <<endl;
cout<<"The price of "<<product2.first<<" is $"<<product2.second <<endl;
cout<<"The price of "<<product3.first<<" is $"<<product3.second <<endl;
return 0;
}
$ g++ pairs.cpp $ a.out The price of lightbulbs is $0.99 The price of shoes is $39.9 The price of tomatoes is $2.3 ------------------ (program exited with code: 0) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Practice Computer Science MCQs
- Check Programming Books
- Check Computer Science Books
- Apply for Computer Science Internship
- Practice Design & Analysis of Algorithms MCQ