Re: how do I find an item in std::list?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Jack <jl@xxxxxxxxxx> wrote:
struct _myval
{
long idx;
std::string src_val;
std::string dst_val;
} myval;
list<_myval> g_myval;

std::string::iterator it = std::find (g_myval.begin(), g_myval.end(),
"hello");

Say I 'd to get src_val from the find function, what should I do?

You need to either define operator==(const _myval&, const string&) that
would compare the struct's src_val field to a given string, or else
write a comparison predicate doing the same and use find_if.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Ibrahim Ferrer
    ... >>> BTW, my ribs will NEVER compare to the ones Jack ...
    (alt.smokers.cigars)
  • Re: Commodore 64 VS the Colecovision
    ... After some careful consideration, Jack, I am going to have to reject ... the Atari 800 was comprable both pricewise and power wise to ... the C=64, and yet they compare the Atari 5200 with the Colecovision, ...
    (rec.games.video.classic)
  • Re: Comparing fractions (or proportions)
    ... Dyslexia is to consider that (when we compare 2 samples) to use ONLY observed quantities? ... IS JACK A TECHNICALLY CREDIBLE PERSON? ...
    (sci.stat.math)
  • Re: Why a form on users computer has missing objects?
    ... I suspect some regional settings (user's name is Chinese) ... Jack ... Please compare these 2 screenshots: ...
    (microsoft.public.vb.general.discussion)
  • Re: Commodore 64 VS the Colecovision
    ... After some careful consideration, Jack, I am going to have to reject ... the Atari 800 was comprable both pricewise and power wise to ... the C=64, and yet they compare the Atari 5200 with the Colecovision, ...
    (rec.games.video.classic)