Beginner C++ student here, first ever programming class. I am trying to put together a program that will identify if a string is all lower case or not. I got as far as the code below. However, I need to account for spaces " ". If there is a space in the string that is input by the user, the program is suppose to return that it is not all lower case. Example:
input: abc def
return: The string is not lower case.
Would any of you ever so kindly advise what would be the best way to account for this in the code below?
NOTE: I know I have 'included' some extra header files, but that is because this is going to be part of another program and this is just an excerpt to get things running.
How about using std::all_of()? It's found in <algorithm>, and it returns true if the condition is true for all elements in the range, false otherwise. Something like this:
1 2 3
std::string string = "abc def";//not a valid string because it has a space
bool valid = std::all_of(string.begin(), string.end(), ::islower);
What's nice about this is that it will account for whitespace characters implicitly, since they aren't considered to be upper- or lowercase characters.