switch (string)
-
Hello guys, how can I use the switch statement with a string, a vector or char[]? Or is there an alternative to this? Thanks and best wishes.
Austrian_Programmer wrote:
how can I use the switch statement with a string, a vector or char[]?
string str = "abc123";
switch(str[0])
{
case 'a':
break;
}"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Austrian_Programmer wrote:
how can I use the switch statement with a string, a vector or char[]?
string str = "abc123";
switch(str[0])
{
case 'a':
break;
}"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
:-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello guys, how can I use the switch statement with a string, a vector or char[]? Or is there an alternative to this? Thanks and best wishes.
Austrian_Programmer wrote:
Or is there an alternative to this?
The gold old
if
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Austrian_Programmer wrote:
Or is there an alternative to this?
The gold old
if
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello guys, how can I use the switch statement with a string, a vector or char[]? Or is there an alternative to this? Thanks and best wishes.
switch only works with integral types.
--Mike-- Visual C++ MVP :cool: LINKS~! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ "That's what's great about doing user interface work. No matter what you do, people will say that what you did was idiotic." -- Raymond Chen
-
There are a lot of different cases, so an if statement won't be such a good choice. Futhermore i want to switch the whole string not just the first letter. In the worst case I've to use a map, combining the strings with integers.
You probably need a hash table.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Hello guys, how can I use the switch statement with a string, a vector or char[]? Or is there an alternative to this? Thanks and best wishes.