I want to make a function call based on the input string given by the user.
Example:
void hello()
{
cout<< "print hello";
}
void hello_world()
{
cout<<"print hello_world";
}
int main()
{
string func_name;
cout<< "enter the function you would like to call: \n 1.Hello \n 2.Hello_world";
cin>> func_name;
func_name();
}
std::mapwhere the function names are the keys and the function pointers the values. If you want to call any arbitrary function, then the answer is no (at least in plain C++).