vector < map < int , char * > > bank;
bank . reserve ( 10 );
if ( bank [ 0 ] [ 0 ] == "a" ) //Memory access error
this code has *two* problems.
one:bank[0] is invalid; the vector is empty. there is no bank[0].
two: the code may not work even if bank[0] refers to a valid element of type
map < int , char * > map<>::operator[] would give a char*&.
operator == would give you a comparison between the two pointers. (what you need is strcmp).
it would be best to change the vector < map < int , char * > > to a
vector < map < int , string> > ; the == will then test equivalence. it could also avoid errors with the pointer being invalid or the c style string pointed to being overwritten.
> my exactly question is how can I use this type of association ( vector < map < type1 , type2 > > )
> without get into Mermory access violation errors? Is there a way to previously
> initialize that association in a manner that allow me to insert new element just doing
> bank [ i ] [ j ] = "some" ;
perhaps you could write a couple of functions
// bank[i][j] = str ;
void insert( map < int , char * >& bank, size_t i,
int j, const char* str )
{
if( bank.size() < (i+1) ) bank.resize(i+1) ;
bank[i][j] = str ; // strdup(str) ?
} // bank[i][j] == str
bool equals( const map < int , char * >& bank, size_t i,
int j, const char* str )
{
return( bank.size() > i ) &&
( bank[i].find(j) != bank[i].end() ) &&
( bank[i][j] != 0 ) &&
( strcmp( bank[i][j], str ) == 0 ) ;
}