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  
 
 [ 3 post ] 

 Relevant Pages 

1. STL/MFC problem with set<string>

2. set<string> in MFC makes troubles

3. Problem Setting Connect String of ADO Control?

4. Reference to item in set<string>: Weird crash with Dinkum STL 2.33

5. How to get & set Env string?

6. String and Character Set

7. Please help to set string value

8. Setting not Null field to ""(empty string) does not work with CRecordset

9. Extracting a set of characters from a string

10. CRecordset setting an empty UNICODE string to Null on Update

11. Please help to set string value

12. Setting up an Array of Strings

 

 
Powered by phpBB® Forum Software