Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <map>
- #include <sstream>
- using namespace std;
- class test1
- {
- private:
- std::string name;
- int age;
- public:
- test1() {};
- test1(std::string name, int age)
- {
- this->name = name;
- this->age = age;
- }
- bool operator < (const test1 & a) const
- {
- return (this->name < a.name) && (this->age < a.age);
- }
- std::string GetName() const
- {
- return this->name;
- }
- int GetAge() const
- {
- return this->age;
- }
- friend ostream & operator << (ostream & os, const test1 & a)
- {
- os << "name: " << a.GetName() << " " << "age : " << a.GetAge();
- return os;
- }
- };
- class test2
- {
- private:
- std::string bag;
- std::string color;
- public:
- test2() {};
- test2(std::string bagName, std::string color)
- {
- this->bag = bagName;
- this->color = color;
- }
- std::string GetBag() const
- {
- return this->bag;
- }
- std::string Color() const
- {
- return this->color;
- }
- friend ostream & operator << (ostream & os, const test2 & a)
- {
- os << "name: " << a.GetBag() << " " << "age : " << a.Color();
- return os;
- }
- };
- int main()
- {
- std::map<test1, test2> myMap;
- test1 user1{ "John", 20 };
- test2 inventory{ "Daykine", "red" };
- myMap.insert(pair<test1, test2>(user1, inventory));
- test1 user2{ "Victor", 20 };
- test2 inventory2{ "Daykine", "blue" };
- myMap.emplace(user2, inventory2);
- test1 user3{ "Victor", 20 };
- test2 inventory3{ "Daykine", "blue" };
- myMap.emplace(user3, inventory3);
- for (auto & item : myMap)
- {
- cout << item.first;
- cout << item.second;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement