The code below generates the resulting output, that is perfectly fine which I need. But I want to save each of those modified vector<int>
in an another vector and then get the output by printing vector<vector<int>>
elements.
I got a template that delivers a formatted output of a vector, but it fails to print an element of vector<vector<int>>
, check by un-commenting code snippets.
Why is this behavior?
How to first assign and then print vector<vector<int>>
elements, such that output remains same as now?
Using C++14(4.9.2)
#include <iostream>
#include <vector>
using namespace std;
#define s(n) scanf("%d",&n)
template<typename T>
inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
{
bool first = true;
os << "[";
for(unsigned int i = 0; i < v.size(); i++)
{
if(!first)
os << ", ";
os << v[i];
first = false;
}
return os << "]";
}
typedef vector<int> vi;
typedef vector< vi > vvi;
int main()
{
int n = 4;
// s(n);
vi list(n, 1);
// vvi rlist;
// int count = 0;
// rlist[count++] = list;
cout << list << "\n";
for (int i = 1; i <= n; ++i)
{
for (int j = n; j >= i; --j)
{
while(list[j] == list[j-1])
{
++list[j];
cout << list << "\n";
// rlist[count++] = list;
}
}
}
return 0;
}