violitation error...need help

Joined
Jan 22, 2008
Messages
1
Reaction score
0
Hello everyone. Working at program i was confused... Please help me out! thks!!

Code:
#include <system.hpp>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <vcl.h>
using  namespace std;

const Hvar=100;
vector< vector< pair<AnsiString,AnsiString> > > table(Hvar);
AnsiString key;
AnsiString data;



//================================================
int freeNumber(int a, AnsiString key, vector< vector< pair<AnsiString,AnsiString> > > *table) {
int i=0;
cout<<"+";
if ( table[a].empty() ) return 0; 
/* brokes here ( when change "*table" to "&table" and "&table" to "table", but compiles correctly ) and writes "Project project1.exe raised exceprional class EAccessViolitation with message 'Access violitation at address 400068A4. Write of address 00000000'... */

cout<<"+";

for ( ; i<= table[a].size(); i++ ) 
{
   cout<<"+";
   if ( table[a][i].first == key) return i;   /* when trying to compile, writes "[C++ Error]Unit1.cpp(53):E2316 'first' is not a member of 'vector<pair<AnsiString,AnsiString>,allocator<pair<AnsiString,AnsiString> > >' "  */

   cout<<"+";
}
return ++i;
}
//================================================
bool Add(int Hvar,vector< vector< pair<AnsiString,AnsiString> > > *table){
AnsiString key;
AnsiString data;
string temp1;
string temp2;
cout<<"enter key and data\n";
cin >> temp1;
cin >> temp2;
//key=AnsiString(temp1.c_str());
key=temp1.c_str();
//data=AnsiString(temp2.c_str());
data=temp2.c_str();
int a=toHash(key,Hvar);


table[a][freeNumber(a,key,&table)].first=key;
table[a][freeNumber(a,key,&table)].second=data;
if (table[a][freeNumber(a,key,&table)].first==key)
if (table[a][freeNumber(a,key,&table)].second==data)
return 1;
return 0;
}
//================================================
int main(){
if (Add(Hvar,&table)) 
cout<<" element added \n";
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top