for(i=0;i<vector.size()-1;++i)
size_t is unsigned integer, so size()-1 is not -1. We should use i+1<vector.size() instead.
size_t
size()-1
-1
i+1<vector.size()