c++ - Segmentation fault while trying to print size of a vector inside a structure -


this piece of code gives me error

struct state{     int time_taken;     vector<int>time_live;     string loc_name;     vector<int>loc; };   for(int u=0;u<(a[start].loc.size());u++) {   l=a[start].loc[1];   if(a[l].time_taken < min_time)   {      min_time=a[l].time_taken;     finish = l;   } } 

this gives segmentational fault .

firstly, if a[start] out of range may problem, may or may not seg fault, depending on a is.

secondly, in loop have a[start].loc[1], out of range if a[start].loc empty. did mean loc[u]?


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -