Switch case Passing String As Parameter

I want to know that if there is any solution for me to run the switch case well. I would like to know that if there is any solution to run the three cases well. Thank you.

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

class alkali
{
char element[5];
public:
void lithium(char element[5])
{
cout << "Name:" << element << endl;
}
};

class steel
{
char element[5];
public:
void sss(char element[5])
{
cout << "Name: " << element << endl;
}
};

int main(int argc, char *argv[])
{
char element[5];
cout << "Please enter element" << endl;
cin >> element;
switch(element)
{
case 'E':
{
alkali a;
a.lithium(element);
break;
}
case 'FW':
{
steel ds;
ds.sss(element);
break;
}
case 'FWF':
{
asd ds;
ds.sss(element);
break;
}
default:
{
cout << "Freak!" << endl;
break;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
anyone know the way to combine element[0],element[0,1] and element[0,1,2] together?
This is the C++ forum. You should be using std::string rather than C-strings/char-arrays.

In any case, switch() won't work on anything besides int or char [or anything convertable to int, but I have no idea what that includes].
How to switch on a string
http://www.cplusplus.com/forum/beginner/13528/#msg65188

If you don't use the std::string, you must use the find_if() algorithm and provide a function that returns whether strcmp() == 0.

Good luck!
Topic archived. No new replies allowed.