I am still working two issues, one is it is sorting the licensePlates together now but not in the order I would like here is an example of what the output is:
Code:
315630 4 21 17 34.\
315630 2 21 16 55.\
315630 3 21 17 08.\
315630 1 21 16 27.\
315630 5 21 17 59.\
I am trying to figure out a way to sort them in order by licensePlates and camera order 1-5 so I can calculate their speed.
Second issue is that I am able to get rid of the ':' char in the time but now I am trying to convert it to a int. I have used a few ways and after reading several forums and googling my way through it, it comes back to std::stoi. However it is simply not working. Am I using it wrong? I thought it could be the way I was combining char but string are mutable and I never had a issue combining string like this in the past.
Code:
int Vehicle::getTime(){
std::string s_hour,s_min,s_sec;
int hour,min,sec,time;
//cleaning time format from 05:33:26 to 05 33 26
for (int i=0; i<sizeof(vtime); i++) {
if (vtime[i]==':') {
vtime[i]=' ';
}
}
//set time to hour, minutes and seconds skiping vtime[2] and [5]
//because they are now spaces
s_hour = vtime[0]+vtime[1];
s_min= vtime[3]+vtime[4];
s_sec=vtime[6]+vtime[7];
//convert string to int
hour=std::stoi(s_hour);
min=std::stoi(s_min);
sec=std::stoi(s_sec);
//convert time to total seconds
time= (hour * 60 * 60) + (min * 60) + sec;
return time;
}
If I convert a char to a int, it works. Why is stoi not working?
Code:
int Vehicle::getTime(){
char s_hour,s_min,s_sec;
int hour,min,sec,time;
//cleaning time format from 05:33:26 to 05 33 26
for (int i=0; i<sizeof(vtime); i++) {
if (vtime[i]==':') {
vtime[i]=' ';
}
}
//set time to hour, minutes and seconds skiping vtime[2] and [5]
//because they are now spaces
s_hour = (int)vtime[0]+(int)vtime[1];
s_min= (int)vtime[3]+(int)vtime[4];
s_sec=(int)vtime[6]+(int)vtime[7];
//convert string to int
hour=s_hour;
min=s_min;
sec=s_sec;
//convert time to total seconds
time= (hour * 60 * 60) + (min * 60) + sec;
return time;
}