Original Post
Is there any possible way to turn a string into a command line. For example you take in a function name from a user and then use that string to run the function.
int main()
{
string szFunctionName;
getline(cin, szFunctionName);
if(szFunctionName=="Add" || szFunctionName=="Subt")
szFunctionName.c_str()();
else
cout<<"That function does not exist.";
}
void Add()
{
cout<<"running";
}
void Subt()
{
cout<<"running";
}
I have tried this but it doesn''t work. Is there any other way to do this without having a long list of functions and a larger if or switch statement?