Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,

I started using vectors just recently, to store large number of data. The data consits of more than a 1000 rows with about 10 values in each row.

To retrieve the first and last value, I used the begin and end attribute of vector:-

C++
double startTime, endTime; 
vector<MyClass> DataTable; // The MyClass has variables that holds the variables from the data. 


In order to retrieve the first and last values of one of the variable : time, I used :
C++
startTime =  DataTable.begin()->time; 
endTime    = DataTable.end()->time; 

The startTime works fine, but when it reaches the endTime value, I get an error that says : "Vector Iterator not dereferencable ". Can't figure out why.. Any suggestions ?
Posted
Updated 12-Mar-18 3:43am

1 solution

vector::end method returns an iterator referring to the past-the-end element (i.e. a guard, see here[^] ). you might use vector::back[^] , instead.
 
Share this answer
 
v2
Comments
Sumal.V 24-Aug-12 8:56am    
Yeah that works :)Cheers :)

The only change being the reference type. Here "." is used instead of "->" operator.
Wendelius 24-Aug-12 17:29pm    
Nice!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900