Push_back vector to another vector

I want push_back()vector Min vector N.

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int i = -1;
    vector<vector<int> >N,
    vector<int>M;
    int temp;

    while (i++ != 5)
    {
        cin >> temp;
        N.push_back(temp);
    }

    N.push_back(vector<int>M);
    return 0;
}

Compilation error

I get a syntax error.

test.cpp: In function ‘int main()’:
test.cpp:28: error: invalid declarator before ‘M’
test.cpp:34: error: no matching function for call tostd::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::push_back(int&)’
/usr/include/c++/4.4/bits/stl_vector.h:733: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]
test.cpp:37: error: ‘M’ was not declared in this scope
coat@thlgood:~/Algorithm$ 
+5
source share
4 answers

You need

M.push_back(temp);

in a while loop, except for the invalid syntax specified in @StilesCrisis answer.

+3
source

This line

N.push_back(vector<int>M);

it should be

N.push_back(M);

Besides

vector<vector<int> >N,

it should be

vector<vector<int> >N;
+5
source

You have few small mistakes.

You can solve them by looking at each of the compilation errors, and think what that means. If the error is fuzzy, you can look at the line number of the error and think what might cause it.

See working code:

int main()
{
    int i = -1;
    vector<vector<int> >N;
    vector<int>M;
    int temp;

    while (i++ != 5)
    {
        cin >> temp;
        M.push_back(temp);
    }

    N.push_back(M);
    return 0;
}
+3
source
N.insert(N.end(),M.begin(),M.end());
0
source

All Articles