Почему оператор switch нельзя применить к строкам?C++

Программы на C++. Форум разработчиков
Anonymous
Почему оператор switch нельзя применить к строкам?

Сообщение Anonymous »


Compiling the following code gives the error message: type illegal.

int main() { // Compilation error - switch expression of type illegal switch(std::string("raj")) { case"sda": } } You cannot use string in either switch or case. Why? Is there any solution that works nicely to support logic similar to switch on strings?


Источник: https://stackoverflow.com/questions/650 ... to-strings

Вернуться в «C++»