I want to evaluate a string with a switch but when I read the string entered by the user throws me the following error.
#include<iostream> using namespace std; int main() { string a; cin>>a; switch (string(a)) { case "Option 1": cout<<"It pressed number 1"<<endl; break; case "Option 2": cout<<"It pressed number 2"<<endl; break; case "Option 3": cout<<"It pressed number 3"<<endl; break; default: cout<<"She put no choice"<<endl; break; } return 0; }
error: invalid cast from type ‘std::string {aka std::basic_string}’ to type ‘int