Click here to Skip to main content
15,887,928 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: using std::find in while loop Pin
josda100024-May-10 5:15
josda100024-May-10 5:15 
GeneralRe: using std::find in while loop Pin
b-rad31124-May-10 5:19
b-rad31124-May-10 5:19 
GeneralRe: using std::find in while loop Pin
josda100024-May-10 5:27
josda100024-May-10 5:27 
GeneralRe: using std::find in while loop Pin
b-rad31124-May-10 5:28
b-rad31124-May-10 5:28 
AnswerRe: using std::find in while loop Pin
David Crow24-May-10 5:28
David Crow24-May-10 5:28 
GeneralRe: using std::find in while loop Pin
b-rad31124-May-10 5:45
b-rad31124-May-10 5:45 
AnswerRe: using std::find in while loop Pin
Richard MacCutchan24-May-10 5:33
mveRichard MacCutchan24-May-10 5:33 
AnswerRe: using std::find in while loop Pin
Aescleal24-May-10 6:01
Aescleal24-May-10 6:01 
The problem is that when std::find succeeds it's referring to an element holding a zero. At the moment when you call std::find again the first element in the range with a zero in it is the one it's just found.

for( std::vector<long double>::iterator start = v.begin(); start != v.end(); )
{
    start = std::find( start, v.end(), 0 );
    if( start != v.end() )
    {
        indices.push_back( start - v.begin() );
        ++start;
    }
}

You can probably collapse a few of the lines down a bit but it's probably not worth it unless you like code to tease the reader.

The important differences between this and your original version is the ++start line. If you find a zero it bumps the iterator past it so the next call to find doesn't return hit the same thing again.

Cheers,

Ash

PS: This is actually just what David and Richard said in their posts, I'll read the entire thread next time before answering Smile | :)
GeneralRe: using std::find in while loop Pin
b-rad31124-May-10 10:31
b-rad31124-May-10 10:31 
QuestionDo I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
ForNow24-May-10 4:48
ForNow24-May-10 4:48 
AnswerRe: Do I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
Code-o-mat24-May-10 5:25
Code-o-mat24-May-10 5:25 
GeneralRe: Do I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
ForNow24-May-10 6:48
ForNow24-May-10 6:48 
GeneralRe: Do I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
Code-o-mat24-May-10 7:28
Code-o-mat24-May-10 7:28 
GeneralRe: Do I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
ForNow24-May-10 17:26
ForNow24-May-10 17:26 
GeneralRe: Do I have to instantiate a copy of IRichEditOle before using EM_GETOLEINTERFACE Pin
Code-o-mat24-May-10 21:34
Code-o-mat24-May-10 21:34 
QuestionListview Pin
wael_r24-May-10 3:19
wael_r24-May-10 3:19 
AnswerRe: Listview Pin
Xeqtr24-May-10 3:33
Xeqtr24-May-10 3:33 
Questiondrawing water in open gl in visual c++ Pin
nearest24-May-10 1:01
nearest24-May-10 1:01 
AnswerRe: drawing water in open gl in visual c++ Pin
Maximilien24-May-10 1:26
Maximilien24-May-10 1:26 
AnswerRe: drawing water in open gl in visual c++ Pin
Nuri Ismail24-May-10 2:55
Nuri Ismail24-May-10 2:55 
QuestionRemote Computer access Pin
hellogany23-May-10 23:35
hellogany23-May-10 23:35 
AnswerRe: Remote Computer access Pin
Richard MacCutchan23-May-10 23:47
mveRichard MacCutchan23-May-10 23:47 
QuestionRe: Remote Computer access Pin
David Crow24-May-10 3:06
David Crow24-May-10 3:06 
AnswerRe: Remote Computer access Pin
ThatsAlok25-May-10 1:50
ThatsAlok25-May-10 1:50 
QuestionCFileDialog not displaying existing files [modified] Pin
maycockt23-May-10 23:34
maycockt23-May-10 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.