C++ switch statements only work with some data types (mostly ints) - not with std::strings. Even so, that's pretty ugly syntax.Some languages allow this:
switch(name){ case "Tiffany": case "tiffany": case "Tiffany McClure": ... break; default: ... }Close enough?
Show differencesHistory of post edits
#ActualServant of the Lord
Posted 16 July 2012 - 02:52 PM
#1Servant of the Lord
Posted 16 July 2012 - 02:51 PM
C++ switch statements only work with some data types (mostly ints) - not with std::strings. Even so, that's pretty ugly syntax.Some languages allow this:
if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")
Am I the only one thinking that looks pretty elegant? Is there any language that implements this way of checking the same variable for different boolean cases?
It looks to me like "Tiffany" is the real string to look for here, so I would convert to lowercase and check for "tiffany".. what if she wrotes "Tiffany Cupcake" ?You'll miss that.
switch(name){ case "Tiffany": case "tiffany": case "Tiffany McClure": ... break; default: ... }Close enough?