switch with a string

Dec 26, 2014 at 10:44am
Is there a way to do that?:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;
int a = 0;
string save = "ccc";

int main(){

	switch(std::atoi(save.c_str()))
	{
	case "ccc": a = 5;
	 default:
		break;
	}

	std::cout << a << endl;//should be 5
	getchar();
}

Dec 26, 2014 at 11:51am
No, switch works only with integer values. You either have to convert string to integer somehow but it's much easier to use if statements instead
Dec 26, 2014 at 11:58am
Thank's for the help!
I've already thought that to me.
Dec 26, 2014 at 1:23pm
closed account (z05DSL3A)

http://www.cplusplus.com/forum/beginner/138012/#msg731831
Dec 26, 2014 at 1:25pm
Thank you Grey Wolf
Topic archived. No new replies allowed.