Set of strings
Author Message
Set of strings

Hi,

I'm trying to find out if there is an easy way to implement a set of string.
I'm trying to avoid using the switch statement so that if I have more
operators to had, there is only one place to make the change.For instance I
have a set of operators:

Operators = {like, <, >, =, >=, <=}

I was wandering if we can implement this set and then define variables that
we can check if they belong to the set or not! Thanks.

Tue, 25 Feb 2003 23:26:48 GMT
Set of strings

Well, it's not entirely clear to me what you are trying to do.
The context is not very clear.  Maybe you could be more explicit
about what you are trying to do?

But you could make a map that holds the name of the operator
as the key, and the operators themselves as the value. Though,
as I said, it's not clear this is what you want.  Nor what
this has to do with a switch.
--
Dan Evens
Standard disclaimers etc. No spam please.

Quote:
> I'm trying to find out if there is an easy way to implement a set of
string.
> I'm trying to avoid using the switch statement so that if I have more
> operators to had, there is only one place to make the change.For instance
I
> have a set of operators:

> Operators = {like, <, >, =, >=, <=}

> I was wandering if we can implement this set and then define variables
that
> we can check if they belong to the set or not! Thanks.

Tue, 25 Feb 2003 23:38:40 GMT
Set of strings

Quote:

> Hi,

> I'm trying to find out if there is an easy way to implement a set of
string.
> I'm trying to avoid using the switch statement so that if I have more
> operators to had, there is only one place to make the change.For instance
I
> have a set of operators:

> Operators = {like, <, >, =, >=, <=}

> I was wandering if we can implement this set and then define variables
that
> we can check if they belong to the set or not! Thanks.

#include <set>
#include <string>

int main() {
std::set<std::string> foo;

foo.insert( "string1" );
foo.insert( "string2" );
if( foo.find( "string1" ) != foo.end() )
std::cout << "in set" << std::endl;
else
std::cout << "not in set" << std::endl;
if( foo.find( "blah" ) != foo.end() )
std::cout << "in set" << std::endl;
else
std::cout << "not in set" << std::endl;
return( 0 );

Quote:
}

Wed, 26 Feb 2003 23:56:49 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages