I installed the latest version of CB with mingw and when I try to debug the attached code I get the following error message which points at the declaration of the 2d temp vector: "no matching function for call to 'std::vector<std::vector<int ..." . If I use a 1d vector it works. Any suggestions?
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int main()
{ // main
int j = 0, h = 0;
vector< vector< int > > temp ( 5, 0 );
for (h = 0; h < 5; ++h){for (j = 0; j < 5; ++j){temp[h].push_back(j); cout << setw(2) << temp[h][j];}}
system("PAUSE");
} // end main
#1: didn't try.
#2:
-------------- Build: Debug in junk ---------------
Compiling: main.cpp
In file included from c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/vector:65,
from C:\Cpp\junk\main.cpp:4:
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_vector.h: In member function 'void std::vector<_Tp, _Alloc>::_M_initialize_dispatch(_Integer, _Integer, std::__true_type) [with _Integer = int, _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]':
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_vector.h:303: instantiated from 'std::vector<_Tp, _Alloc>::vector(_InputIterator, _InputIterator, const _Alloc&) [with _InputIterator = int, _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]'
C:\Cpp\junk\main.cpp:17: instantiated from here
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_vector.h:991: error: no matching function for call to 'std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_fill_initialize(size_t, int&)'
c:\codeblocks\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_vector.h:1033: note: candidates are: void std::vector<_Tp, _Alloc>::_M_fill_initialize(size_t, const _Tp&) [with _Tp = std::vector<int, std::allocator<int> >, _Alloc = std::allocator<std::vector<int, std::allocator<int> > >]
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
This is not a CB related problem. Check the initialization of temp. Try this one: vector< vector< int > > temp(5);