In my book, it says find() must be used like so:
iter = var.find(scores.begin(), scores.end(), score);

but later it uses this in practice:

while (used.find(guess) != string::npos)

Why can you simply pass 'guess' var to it here and not need to search a range? Isn't find() an algorithm that requires 3 arguments to work?
*Guess is 'char guess' declared earlier.

Ok I see. so find() operates differently depending which type of variable it's being used on, and what type of arguments are being passed to it right?

The find() in algorithm is completely independent of find() in string. find() in algorithm should be able to be used on any STL container (including std::string if I am not mistaken). The find() in string can only be used from a string object and takes different kinds of parameters as overloads (see those references I posted).

I should have mentioned that used was declared ahead of the code as:

string used = "";

But now I'm curious about this reference you're making. What makes one find() an Algorithm, and another a Member function? I'm looking through the links you sent me, and maybe it's my newb-ness getting in the way, but how do you tell the difference?

What is the type of var in your above code? The <algorithm> versions are not member functions of an object as normally they take iterators to objects as parameters. That's why I'm confused as to where var is coming from. I misread it initially.

Edited 6 Years Ago by jonsca: n/a

Just to add, you can declare multiple functions with the same name in the same namespace as long as the arguments are different. This is called function overloading.

Edited 6 Years Ago by LevyDee: n/a

This article has been dead for over six months. Start a new discussion instead.