switch with a string

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();
}

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
Thank's for the help!
I've already thought that to me.
closed account (z05DSL3A)

http://www.cplusplus.com/forum/beginner/138012/#msg731831
Thank you Grey Wolf
Topic archived. No new replies allowed.