【发布时间】:2011-12-07 07:51:50
【问题描述】:
我想将push_back()一个向量M转换成向量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;
}
编译错误
我收到语法错误。
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$
【问题讨论】:
-
让我们为新社区成员提供改进建议。我同意,错误消息很有帮助。
-
@Nicol:Yucoat 已更新问题以包含错误消息。 :)