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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in Data Structure I
- Participate in Data Structure I Certification Contest
- Become a Top Ranker in Data Structure I
- Take Data Structure I Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice Programming MCQs
- Apply for Information Technology Internship
- Apply for Data Structure Internship
- Buy Data Structure Books
- Practice Computer Science MCQs