Why does the following code stop after the display of just one "1st for" message ?, so I guess it doesn't even get into that first if ... When I say it stops I mean the process stops with exit value -1. I guess there should be no elements in the vector when it enters in that first for , but why does it stop after exactly one :"1st for" message ?
Do I have to catch any exceptions for std::vector ?
Code:
std::vector<KeepAliveMsg> vec;
std::vector<KeepAliveMsg>::iterator p;
for(p=vec.begin();p != vec.end();p++)
{ //a=(*p).pid;
//b=ob.get_qbuf().pid;
std::cout<<i++<<"."<<" 1st for"<<std::endl;
if( ( (*p).pid)==ob.get_qbuf().pid )
{
std::cout<<i++<<"."<<"wdog before timestamp update"<<std::endl;
(*p).timestamp=ob.get_qbuf().timestamp;
timestamp_changed=true;
}
}//for
if(!timestamp_changed)
{
std::cout<<i++<<"."<<" wdog before push_back in vec"<<std::endl;
vec.push_back(ob.get_qbuf());
std::cout<<i++<<"."<<"wdo after push_back in vec"<<std::endl;
if ( vec.size() != 0 )
std::cout<<"Last element: "<<vec.back().pid<<std::endl;
}