qt - switch/case statement in C++ with a QString type -


I want to use switch-case in my program but the compiler generates an error. How can I use the switch statement with QString ?

The compiler gives me this error:

  The expression of the switch type 'QString' is invalid   

My code is as follows :

  boolStopWord (the word QString) {bool flag = false; Switch (word) {case "the": flag = true; break ; "On" case: flag = true; break ; Case "in": flag = true; break ; Case "your": flag = true; break ; Case "near": flag = true; break ; Case "all": flag = true; break ; Case "this": flag = true; break ; } Return flag; }    

How do I use the switch statement with a Caststring ?

You can not use the switch statement in C ++ language with integral or enum types. You can formally enter the square type of object in the switch statement, but this means that the compiler will look for a user-defined conversion to convert it to an integral or enum type.

Comments