Below what do I add to my switch statements to code "for all the rest that are not listed"(sic). I have conditions for D, d, H, h no prob. But H and h will report a false as it should but which would be the state if something off-the-wall were entered. So I want to discriminate further.
PS I know ways of making this better without enums etc., but I am interested in the solution posted.
Also make your life easier by using the std::toupper function, this will halve your logic.
Using an enum like that with bool is perhaps not a good use of an enum.
If you configure your editor to convert tabs to 4 spaces say, your code will display much better here. This site converts tabs to 8 spaces, resulting in excessive indenting.
for (auto & elem:str)
{
str[elem] = std::toupper(str[elem],loc);
}
should be
1 2 3 4
for (auto & elem:str)
{
elem = std::toupper(elem,loc);
}
Note, the first version is accessing out of range elements of the string.
str[elem] uses each letter in turn as the subscript,
str['c'] which is str[99] in the ASCII table.
str['w'] which is str[119] in the ASCII table.
It leaves the string unchanged - but corrupts some other area of memory.
I guess in a for-each loop you can't use the array (str) as a subscripted data structure. It is the container design that you don't need to keep track of things, hence your solution has no subscripts. Or, are there any scenarios where you would do some thing like str[item#]?
Used correctly, you won't need boundary checking in the for-each scenario.
If you configure your editor to convert tabs to 4 spaces say, your code will display much better here. This site converts tabs to 8 spaces, resulting in excessive indenting.
In my IDE's editor , I never need to use the tab key - it does indenting by itself, and uses spaces to do so. If I were to use the tab key, it converts those to spaces as well. There should be some settings somewhere to configure this.