c++ - Can't access vector element? -


i have code

vector <int> a[100001]; a[1].push_back(1); if( a[1][0] == 1)       cout<<"ok!"; 

but when try access a1[0] says:

cxx0058: error: overloaded operator not found 

full code:

#include<stdio.h> #include<vector> using namespace std; file *f=fopen("chei.in","r"); file *g=fopen("chei.out","w"); int t[100001],n,x,nr,k,d; vector <int> a[100001]; int main(){     fscanf(f,"%d",&n);     for(int i=1;i<=n;++i)     { fscanf(f,"%d",&x);       for(k=0;k<a[i].size();++k){                if( a[i][k]== x)                    break;}       if(k==0 || ( k==a[x].size() && a[i][k] == x )){               t[i]=x;               a[x].push_back(i);       }     } for(int i=1;i<=n;i++){         if(t[i]==i || t[i]==0)             nr++;} fprintf(g,"%d",nr); return 0; } 

here's screenshot of watch: alt text

there doesn't seem wrong code. thought meant compile error, ybungalobill pointed out retrieving results of operator not supported visual studio's debugger.

this isn't worry if program expect do. program can access vector element fine, if debugger bit confused.

to allow debugger report value, try setting watch so: ((a[1])._myfirst)[0] per recommendation in thread: http://social.msdn.microsoft.com/forums/en-us/vsdebug/thread/c09f4fe4-4783-4dbb-8d36-85489fa2a4ae


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -