현재 작업중인 게임에서 플레이어의 움직임 기록을 인쇄하려고합니다. 각 라운드가 끝날 때마다 모든 플레이어는 양수 또는 음수 방향으로 약간의 양을 이동했으며 이것은 이동 벡터에 int로 기록됩니다. 결국 나는 각 플레이어의 이동 시간 대 이동 방향을 계획하고 싶지만 2d 벡터에서 데이터를 추출하는 데 문제가 있습니다.2 차원 STL 벡터 반복 C++
그래서 난 그냥 반복하고 모든 요소를 인쇄하는 것이었다 시도 우선, 그러나이 컴파일되지 않습니다 :
void output_movement(const std::vector< std::vector<int> > & movement){
std::vector< std::vector<int> >::iterator row;
std::vector<int>::iterator col;
for (row = movement.begin(); row != movement.end(); ++row) {
for (col = row->begin(); col != row->end(); ++col) {
std::cout << **col;
}
}
}
을 컴파일러는 정말하지 않습니다 이해이 오류 메시지 제공 :
를hg_competition.cpp:45: error: no match for ‘operator=’ in ‘row = ((const std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >*)money_movement)->std::vector<_Tp, _Alloc>::begin [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]()’
/usr/include/c++/4.4/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >& __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >::operator=(const __gnu_cxx::__normal_iterator<std::vector<int, std::allocator<int> >*, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > >&)
도움을 주시면 대단히 감사하겠습니다.
나는 만약 당신이 다시 쓰려고한다면 e 코드를 사용한다면 적절한 범위 지정을 위해'for' 루프 내에'row'와'col' 선언을 적절하게 넣는 것도 가치가 있습니다. –
또한 아마도'output_movement'가'operator <<'처럼 불려지는 것처럼 C++이 될 것입니다. – Philipp
@Matthieu 귀하의 제안을 포함하도록 답변을 업데이트했습니다. –