forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex11_12_13.cpp
33 lines (30 loc) · 1008 Bytes
/
ex11_12_13.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// ex11_12_13.cpp
// Exercise 11.12 11.13
//
// Created by pezy on 12/15/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// Write a program to read a sequence of strings and ints,
// storing each into a pair. Store the pairs in a vector.
//
// There are at least three ways to create the pairs in the program for the previous exercise.
// Write three versions of that program, creating the pairs in each way.
// Explain which form you think is easiest to write and understand, and why.
#include <vector>
#include <utility>
#include <string>
#include <iostream>
int main()
{
std::vector<std::pair<std::string, int>> vec;
std::string str;
int i;
while (std::cin >> str >> i)
vec.push_back(std::pair<std::string, int>(str, i));
//vec.push_back(std::make_pair(str, i));
//vec.push_back({str, i});
//vec.emplace_back(str, i); //!!! easiest way.
for (const auto &p : vec)
std::cout << p.first << ":" << p.second << std::endl;
}