Searching a vector for a specific value

Discussion in 'C++' started by Siegen, Sep 24, 2006.

  1. Siegen

    Siegen Guest

    Hi.

    Could anyone tell me how one can search a vector for a specific value?

    std::vector<int> vec;

    vec.push_back(1);
    vec.push_back(2);
    vec.push_back(3);
    vec.push_back(4);

    How to check whether the number three is in the vector?


    I tried "find" but it doesn't appear to be available to "vector".


    Any help appreciated.

    Regards,

    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 24, 2006
    #1
    1. Advertising

  2. Siegen wrote:

    > Could anyone tell me how one can search a vector for a specific value?
    >
    > std::vector<int> vec;
    >
    > vec.push_back(1);
    > vec.push_back(2);
    > vec.push_back(3);
    > vec.push_back(4);
    >
    > How to check whether the number three is in the vector?
    >
    >
    > I tried "find" but it doesn't appear to be available to "vector".



    You posted the same question 3 days ago, and got the correct answer
    from several people:

    http://tinyurl.com/rmozs

    That means one of three things: (1) You didn't bother to read the
    responses to your questions last time, (2) you are a troll, or (3) you
    are a robot that is simply autoposting the question.

    Best regards,

    Tom
     
    Thomas Tutone, Sep 24, 2006
    #2
    1. Advertising

  3. Siegen

    Siegen Guest

    On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone" <> wrote:

    Thomas.

    Thanks for :> http://tinyurl.com/rmozs


    Rather than trying your "Group Gestapo" act, please consider some more realistic
    possibilities such as: my newsreader not "seeing" any replies. Owing to
    circumstances beyond my control, I wasn't able to get back to the group for some
    36+ hours by which time my I.S.P. had, perhaps, dropped "older" messages.

    "Google Groups" is a good, short-term, archive but requires a real email address
    as log-in and, therefore, as fodder for spammers.

    Thanks,


    :> Siegen wrote:
    :>
    :> > Could anyone tell me how one can search a vector for a specific value?
    :> >
    :> > std::vector<int> vec;
    :> >
    :> > vec.push_back(1);
    :> > vec.push_back(2);
    :> > vec.push_back(3);
    :> > vec.push_back(4);
    :> >
    :> > How to check whether the number three is in the vector?
    :> >
    :> >
    :> > I tried "find" but it doesn't appear to be available to "vector".
    :>
    :>
    :> You posted the same question 3 days ago, and got the correct answer
    :> from several people:
    :>
    :> http://tinyurl.com/rmozs
    :>
    :> That means one of three things: (1) You didn't bother to read the
    :> responses to your questions last time, (2) you are a troll, or (3) you
    :> are a robot that is simply autoposting the question.
    :>
    :> Best regards,
    :>
    :> Tom

    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 24, 2006
    #3
  4. Siegen

    Duane Hebert Guest

    "Siegen" <> wrote in message
    news:...
    > Hi.
    >
    > Could anyone tell me how one can search a vector for a specific value?
    >
    > std::vector<int> vec;
    >
    > vec.push_back(1);
    > vec.push_back(2);
    > vec.push_back(3);
    > vec.push_back(4);
    >
    > How to check whether the number three is in the vector?
    >
    >
    > I tried "find" but it doesn't appear to be available to "vector".
    >
    >
    > Any help appreciated.


    std::find() ?
     
    Duane Hebert, Sep 24, 2006
    #4
  5. Siegen

    Siegen Guest

    On Sun, 24 Sep 2006 09:37:30 -0400 "Duane Hebert" <> wrote:

    Thanks Duane.

    I got stuck expecting a member function instead of a general algorithm .
    :> std::find() ?
    :>
    I'm on the right track now.

    Regards,


    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 24, 2006
    #5
  6. Siegen wrote:

    > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone" <> wrote:
    >
    > :> Siegen wrote:
    > :>
    > :> > Could anyone tell me how one can search a vector for a specific value?
    > :> >
    > :> > std::vector<int> vec;
    > :> >
    > :> > vec.push_back(1);
    > :> > vec.push_back(2);
    > :> > vec.push_back(3);
    > :> > vec.push_back(4);
    > :> >
    > :> > How to check whether the number three is in the vector?
    > :> >
    > :> >
    > :> > I tried "find" but it doesn't appear to be available to "vector".
    > :>
    > :>
    > :> You posted the same question 3 days ago, and got the correct answer
    > :> from several people:
    > :>
    > :> http://tinyurl.com/rmozs
    > :>
    > :> That means one of three things: (1) You didn't bother to read the
    > :> responses to your questions last time, (2) you are a troll, or (3) you
    > :> are a robot that is simply autoposting the question.


    > Thomas.
    >
    > Thanks for :> http://tinyurl.com/rmozs


    You're welcome.

    > Rather than trying your "Group Gestapo" act


    Hmm, that seems a bit strong.

    > , please consider some more realistic
    > possibilities such as: my newsreader not "seeing" any replies. Owing to
    > circumstances beyond my control, I wasn't able to get back to the group for some
    > 36+ hours by which time my I.S.P. had, perhaps, dropped "older" messages.
    >
    > "Google Groups" is a good, short-term, archive but requires a real email address
    > as log-in and, therefore, as fodder for spammers.


    Actually, Google Groups does not require a real email address or a
    log-in just to read (as opposed to post) - as the link I referred you
    to demonstrates.

    Anyway, I'm sorry if my actions offended you - as they certainly must
    have since you have compared me to Hitler's secret police.

    Best regards,

    Tom
     
    Thomas Tutone, Sep 24, 2006
    #6
  7. Siegen

    Rolf Magnus Guest

    Please don't top-post.

    Siegen wrote:

    > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone" <>
    > wrote:
    >
    > :> Siegen wrote:
    > :>
    > :> > Could anyone tell me how one can search a vector for a specific
    > :> > value?
    > :> >
    > :> > std::vector<int> vec;
    > :> >
    > :> > vec.push_back(1);
    > :> > vec.push_back(2);
    > :> > vec.push_back(3);
    > :> > vec.push_back(4);
    > :> >
    > :> > How to check whether the number three is in the vector?
    > :> >
    > :> >
    > :> > I tried "find" but it doesn't appear to be available to "vector".
    > :>
    > :>
    > :> You posted the same question 3 days ago, and got the correct answer
    > :> from several people:
    > :>
    > :> http://tinyurl.com/rmozs
    > :>
    > :> That means one of three things: (1) You didn't bother to read the
    > :> responses to your questions last time, (2) you are a troll, or (3) you
    > :> are a robot that is simply autoposting the question.
    >
    >
    > Thanks for :> http://tinyurl.com/rmozs
    >
    >
    > Rather than trying your "Group Gestapo" act, please consider some more
    > realistic possibilities


    The above ones are realistic. I have seen all of them here.

    > such as: my newsreader not "seeing" any replies. Owing to circumstances
    > beyond my control, I wasn't able to get back to the group for some 36+
    > hours by which time my I.S.P. had, perhaps, dropped "older" messages.


    Hmm, 36 hours is a very short age for a message to be dropped. Often,
    messages need several hours to even distribute through all of Usenet, so
    the time window to actually see messages would be quite short if they get
    dropped after 36 hours.
    Maybe you could switch to a better news server. There are some servers that
    can be used for free.

    > "Google Groups" is a good, short-term, archive but requires a real email
    > address as log-in and, therefore, as fodder for spammers.


    I don't need any log-in to read the archives, so I guess you must be doing
    something wrong.
     
    Rolf Magnus, Sep 24, 2006
    #7
  8. Siegen

    Duane Hebert Guest

    "Siegen" <> wrote in message
    news:eek:...
    > On Sun, 24 Sep 2006 09:37:30 -0400 "Duane Hebert" <> wrote:
    >
    > Thanks Duane.
    >
    > I got stuck expecting a member function instead of a general algorithm .
    > :> std::find() ?
    > :>
    > I'm on the right track now.


    Some containers have specialized algorithms
    so you should check there first. If not, then
    look at algorithm.
     
    Duane Hebert, Sep 24, 2006
    #8
  9. Siegen

    Siegen Guest

    On 24 Sep 2006 07:10:15 -0700 "Thomas Tutone" <> wrote:

    Tom,
    I did get a bit "heavy" so I apologise to you for my comparison.
    I also apreciate the assistance I obtained from you and the others.

    As for the "google" groups, I can just get a "yahoo" or whatever "throw-away"
    address I presume.

    Cheers,



    :>
    :> Siegen wrote:
    :>
    :> > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone" <> wrote:
    :> >
    :> > :> Siegen wrote:
    :> > :>
    :> > :> > Could anyone tell me how one can search a vector for a specific value?
    :> > :> >
    :> > :> > std::vector<int> vec;
    :> > :> >
    :> > :> > vec.push_back(1);
    :> > :> > vec.push_back(2);
    :> > :> > vec.push_back(3);
    :> > :> > vec.push_back(4);
    :> > :> >
    :> > :> > How to check whether the number three is in the vector?
    :> > :> >
    :> > :> >
    :> > :> > I tried "find" but it doesn't appear to be available to "vector".
    :> > :>
    :> > :>
    :> > :> You posted the same question 3 days ago, and got the correct answer
    :> > :> from several people:
    :> > :>
    :> > :> http://tinyurl.com/rmozs
    :> > :>
    :> > :> That means one of three things: (1) You didn't bother to read the
    :> > :> responses to your questions last time, (2) you are a troll, or (3) you
    :> > :> are a robot that is simply autoposting the question.
    :>
    :> > Thomas.
    :> >
    :> > Thanks for :> http://tinyurl.com/rmozs
    :>
    :> You're welcome.
    :>
    :> > Rather than trying your "Group Gestapo" act
    :>
    :> Hmm, that seems a bit strong.
    :>
    :> > , please consider some more realistic
    :> > possibilities such as: my newsreader not "seeing" any replies. Owing to
    :> > circumstances beyond my control, I wasn't able to get back to the group for some
    :> > 36+ hours by which time my I.S.P. had, perhaps, dropped "older" messages.
    :> >
    :> > "Google Groups" is a good, short-term, archive but requires a real email address
    :> > as log-in and, therefore, as fodder for spammers.
    :>
    :> Actually, Google Groups does not require a real email address or a
    :> log-in just to read (as opposed to post) - as the link I referred you
    :> to demonstrates.
    :>
    :> Anyway, I'm sorry if my actions offended you - as they certainly must
    :> have since you have compared me to Hitler's secret police.
    :>
    :> Best regards,
    :>
    :> Tom

    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 25, 2006
    #9
  10. Siegen

    Siegen Guest

    Aren't you "top-posting"? Why can't I?

    Bye the way. When did you actually buy me? You're acting like you own me.

    Regards <If I may>



    On Sun, 24 Sep 2006 16:28:55 +0200 Rolf Magnus <> wrote:
    :> Please don't top-post.
    :>
    :> Siegen wrote:
    :>
    :> > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone" <>
    :> > wrote:
    :> >
    :> > :> Siegen wrote:
    :> > :>
    :> > :> > Could anyone tell me how one can search a vector for a specific
    :> > :> > value?
    :> > :> >
    :> > :> > std::vector<int> vec;
    :> > :> >
    :> > :> > vec.push_back(1);
    :> > :> > vec.push_back(2);
    :> > :> > vec.push_back(3);
    :> > :> > vec.push_back(4);
    :> > :> >
    :> > :> > How to check whether the number three is in the vector?
    :> > :> >
    :> > :> >
    :> > :> > I tried "find" but it doesn't appear to be available to "vector".
    :> > :>
    :> > :>
    :> > :> You posted the same question 3 days ago, and got the correct answer
    :> > :> from several people:
    :> > :>
    :> > :> http://tinyurl.com/rmozs
    :> > :>
    :> > :> That means one of three things: (1) You didn't bother to read the
    :> > :> responses to your questions last time, (2) you are a troll, or (3) you
    :> > :> are a robot that is simply autoposting the question.
    :> >
    :> >
    :> > Thanks for :> http://tinyurl.com/rmozs
    :> >
    :> >
    :> > Rather than trying your "Group Gestapo" act, please consider some more
    :> > realistic possibilities
    :>
    :> The above ones are realistic. I have seen all of them here.
    :>
    :> > such as: my newsreader not "seeing" any replies. Owing to circumstances
    :> > beyond my control, I wasn't able to get back to the group for some 36+
    :> > hours by which time my I.S.P. had, perhaps, dropped "older" messages.
    :>
    :> Hmm, 36 hours is a very short age for a message to be dropped. Often,
    :> messages need several hours to even distribute through all of Usenet, so
    :> the time window to actually see messages would be quite short if they get
    :> dropped after 36 hours.
    :> Maybe you could switch to a better news server. There are some servers that
    :> can be used for free.
    :>
    :> > "Google Groups" is a good, short-term, archive but requires a real email
    :> > address as log-in and, therefore, as fodder for spammers.
    :>
    :> I don't need any log-in to read the archives, so I guess you must be doing
    :> something wrong.

    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 25, 2006
    #10
  11. Siegen

    Siegen Guest

    On Sun, 24 Sep 2006 11:02:23 -0400 "Duane Hebert" <> wrote:

    :> Some containers have specialized algorithms
    :> so you should check there first. If not, then
    :> look at algorithm.
    Thanks.

    Regards,


    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 25, 2006
    #11
  12. Siegen

    Kai-Uwe Bux Guest

    Siegen wrote [top posting corrected]

    > On Sun, 24 Sep 2006 16:28:55 +0200 Rolf Magnus <>
    > wrote:
    > :> Please don't top-post.
    > :>
    > :> Siegen wrote:
    > :>
    > :> > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone"
    > :> > <> wrote:

    [snip]
    > Aren't you "top-posting"?


    Rolf Magnus was not top posting. Those parts of his post that refer to
    specific sections of yours were properly posted below the quote they refer
    to.

    > Why can't I?


    You can (unfortunately, there is nothing we could do to prevent you :).

    However, top posting is just considered poor form around these parts. Most
    regulars feel rather strongly about it. In this news group, top posting is
    frowned upon.


    > Bye the way. When did you actually buy me? You're acting like you own me.


    You are misinterpreting. "Please don't top post" is not an order to a slave.
    It is a (still friendly) reminder of the local customs in this news group.
    It is a _reminder_, because the issue is dealt with in the FAQ.


    [snip]


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 25, 2006
    #12
  13. Siegen

    Siegen Guest

    On Mon, 25 Sep 2006 06:25:06 -0400 Kai-Uwe Bux <> wrote:

    Please stop dragging this thread <and me> even further off-topic.

    Also, if you do not understand something then please don't re-arrange it. Your
    re-arrangement of my post has me replying to Thomas <see "A" below> when I was
    actually replying to Rolf. In your unsolicited efforts to maintain "Order", you
    are creating Dis-order.

    Regards,

    :> Siegen wrote [top posting corrected]
    :>
    :> > On Sun, 24 Sep 2006 16:28:55 +0200 Rolf Magnus <>
    :> > wrote:
    :> > :> Please don't top-post.
    :> > :>
    :> > :> Siegen wrote:
    :> > :>
    :> > :> > On 24 Sep 2006 05:18:25 -0700 "Thomas Tutone"
    :> > :> > <> wrote:
    :> [snip]
    "A"
    :> > Aren't you "top-posting"?
    :>
    :> Rolf Magnus was not top posting. Those parts of his post that refer to
    :> specific sections of yours were properly posted below the quote they refer
    :> to.

    :> Siegen:
    :> > Why can't I?
    :>
    :> You can (unfortunately, there is nothing we could do to prevent you :).
    :>
    :> However, top posting is just considered poor form around these parts. Most
    :> regulars feel rather strongly about it. In this news group, top posting is
    :> frowned upon.

    :> Siegen:
    :> > Bye the way. When did you actually buy me? You're acting like you own me.

    :> Kai-Uwe Bux
    :> You are misinterpreting. "Please don't top post" is not an order to a slave.
    :> It is a (still friendly) reminder of the local customs in this news group.
    :> It is a _reminder_, because the issue is dealt with in the FAQ.
    :>
    :>
    :> [snip]
    :>
    :>
    :> Best
    :>
    :> Kai-Uwe Bux

    -- Siegen
    ----------------------
    ---------------------
     
    Siegen, Sep 25, 2006
    #13
  14. Siegen

    Kai-Uwe Bux Guest

    Siegen wrote:

    > On Mon, 25 Sep 2006 06:25:06 -0400 Kai-Uwe Bux <> wrote:
    >
    > Please stop dragging this thread <and me> even further off-topic.


    a) Posting etiquette is on-topic.

    b) Again, please refer to the FAQ on how to post around here.


    > Also, if you do not understand something then please don't re-arrange it.
    > Your re-arrangement of my post has me replying to Thomas <see "A" below>
    > when I was actually replying to Rolf. In your unsolicited efforts to
    > maintain "Order", you are creating Dis-order.


    No, I did not create disorder: the first two lines of my re-arrangement
    read:

    Siegen wrote [top posting corrected]

    > On Sun, 24 Sep 2006 16:28:55 +0200 Rolf Magnus <>
    > wrote:

    ...

    it is plain clear that you were replying to a post of Rolf Magnus.


    [snip]


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 25, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pmatos
    Replies:
    6
    Views:
    23,836
  2. Replies:
    8
    Views:
    1,935
    Csaba
    Feb 18, 2006
  3. Siegen
    Replies:
    5
    Views:
    412
    Siegen
    Sep 24, 2006
  4. Javier
    Replies:
    2
    Views:
    573
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    366
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page