question on std::find()

B

Bit byte

I have the ff code:

list<string> *m_alive_list ;
list<string>::iterator my_iter;
my_iter = find(m_alive_list->begin(), m_alive_list->end, string(inbox) ;

Compiler barfs on 2nd line with this error msg:

error C2665: 'std::find' : none of the 3 overloads can convert parameter
1 from type 'std::list<_Ty>::iterator'
with
[
_Ty=std::string
]

I thought the first arg (i.e. ->begin() ) returns an iterator of the
correct type - what gives?
 
B

Bit byte

Correction - compiler barfs on the THIRD line (i.e. line containing the
find() algorithm)
 
P

pasalic.zaharije

Line 3.

1 - put () at end of end methode :)
2 - put ) at end of find function/template
 
B

Bit byte

Line 3.

1 - put () at end of end methode :)
2 - put ) at end of find function/template

That was an obvious typo (did you read the compiler error message).

For those whom the typo was not obvious, here is the corrected line:

my_iter = find(m_alive_list->begin(), m_alive_list->end, string(inbox) );
 
P

pasalic.zaharije

I did not see any problems, here is my code that works;

#include <list>
#include <string>
#include <algorithm>

using namespace std;

list<string> *m_list ;
list<string>::iterator my_iter;

int main()
{
m_list = new list<string>;
my_iter = find(m_list->begin(), m_list->end(), string("dasdas")) ;

delete m_list;
return 0;
}
 
M

Markus Schoder

Bit said:
That was an obvious typo (did you read the compiler error message).

For those whom the typo was not obvious, here is the corrected line:

my_iter = find(m_alive_list->begin(), m_alive_list->end, string(inbox) );

And what about the _other_ obvious typo?

Try

my_iter = find(m_alive_list->begin(),m_alive_list->end(),string(inbox));
 
B

Bit byte

Markus Schoder wrote:

And what about the _other_ obvious typo?

Try

my_iter = find(m_alive_list->begin(),m_alive_list->end(),string(inbox));

<echo>
Doh !!!!!!
</echo>

I think its time for another cofee break...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top