#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int main()
{
vector<vector<int>> v1 = { {1, 2}, {3, 4} };
vector<vector<int>> v2 = { {5, 6}, {7, 8} };
for (int i = 0; i < v1.size(); ++i)
{
transform(v1[i].begin(), v1[i].end(), v2[i].begin(), v1[i].begin(), plus<int>());
}
for (const auto& i : v1)
{
for (const auto& j : i)
{
cout << j << " ";
}
cout << endl;
}
}
Is it possible to print the vectors with more succinct code? With something from algorithm
for example. Thank you.
Output:
6 8
10 12
Aucun commentaire:
Enregistrer un commentaire