I want to push_back()
a vector M
into 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;
}
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 to ‘std::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$
This line
N.push_back(vector<int>M);
should be
N.push_back(M);
Also
vector<vector<int> >N,
should be
vector<vector<int> >N;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With