how to go through a string array and apply functions for different strings?

Posted by Newbie on Stack Overflow See other posts from Stack Overflow or by Newbie
Published on 2010-06-12T20:48:08Z Indexed on 2010/06/12 20:52 UTC
Read the original article Hit count: 146

Filed under:
|

Ok, this may be really noobish question, but i am wishing there is something i dont know yet.

I go through a file, and check which string each line has, depending on the string value i execute a different function for it (or functions).

This is how i do it now:

if(str == "something"){
    // do stuff
}else if(str == "something else"){
    // do stuff
}else if(str == "something more"){
    // do stuff
}else if(str == "something again"){
    // do stuff
}else if(str == "something different"){
    // do stuff
}else if(str == "something really different"){
    // do stuff
}

I am afraid this will become "slow" after i have to repeat those else if lines a lot...

I tried to use switch() statement, but obviously it doesnt work here, is there something similar to switch() to use here?

© Stack Overflow or respective owner

Related posts about c++

Related posts about Windows