• Advertisement

Archived

This topic is now archived and is closed to further replies.

std::find

This topic is 5272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, When i use std::find, i get the error: error C2039: ''find'' : is not a member of ''std''. i''m using vs6.0. thx in advance

Share this post


Link to post
Share on other sites
Advertisement
Shouldn''t you be using something like std::map::find or std::set::find?
find is a member function of these (and other) STL templates.

Share this post


Link to post
Share on other sites
I would guess that you are messing up with namespaces. Your code should look like one of these:

1.

#include <algorithm>

std::find(...);


2.

#include <algorithm>

using std::find;

find(...);


3.

#include <algorithm>

using namespace std;

find(...);


[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

Share this post


Link to post
Share on other sites
quote:
Original post by Strewth
Shouldn't you be using something like std::map::find or std::set::find?
find is a member function of these (and other) STL templates.

Indeed, std::map has an overloaded find() public member function. Freaker13 , though, is talking about std::find(), which is one of the [search/non-mutating] generic algorithms (a set of independent functions). For example:

#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

...

std::vector<std::string> V(..., ...);

std::sort( V.begin(), V.end() ); // generic algorithm `sort'


// (yes, could, and probably would, be put in if statement)

std::vector<int>::iterator found = std::find( V.begin(), V.end(), "word" ); // generic algorithm `found'

if ( found != V.end() )
std::cout << "found" << std::endl;
else
std::cout << "not found" << std::endl;

std::rotate( V.begin(), V.begin() + V.size() / 2, V.end() ); // generic algorithm `rotate'


std::reverse( V.begin(), V.end() ); // generic algorithm `reverse'


... etc., etc.


[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

[edited by - Lektrix on August 16, 2003 8:34:59 AM]

Share this post


Link to post
Share on other sites

  • Advertisement