The problem I have, I have to add to a vector, the missing chars.
For example I have initially
s,a,p,i,e,n,t,i,a
and I have to add missing chars to it
s,a,p,i,e,n,t,i,a,b,c,d …
I am trying to use this code to search for an existing value.
for(char c='a';c!='z';++c)
{
if (vec.end()!=find(vec.begin(),vec.end(),c))
vec.push_back(c);
}
The find returns last when it fails to locate a value. But how do I know if last value was in it?
EDIT
When the for loop starts, for ‘a’ returns vec.end() so it should not go in, but goes in, and adds ‘a’ again in the end.
See this in debugger
alt text http://img203.imageshack.us/img203/2048/bb1f.jpg
(The bug I have, the value in last position gets inserted twice, I have to omit this)
Nope, end() is not the last element of the vector but past it. To iterate over all elements you normally do
So whatever your problem is, this is ok.