I am trying to check if the whole word is upper case, if this is true it should return true, else return false.
My current code is:
#include "UpperCaseFilter.h"
#include "ReadFilteredWords.h"
#include "ReadWords.h"
#include <locale>
bool UpperCaseFilter::filter(string word) {
if(!word.empty()) {
for(int i = 0; i < word.length(); i++) {
if(isupper(word[i])) {
return true;
}
else {
return false;
}
}
}
}
The problem with this code is, if i have for example HeLLO
, it will return true because my last character is true. How would I only return true if the whole string is true. I did it using a counter method but it is not the most efficient.
I also tried using the all_of
method but I think I dont have the correct compiler version because it says all_of isn't defined
(Even with correct imports).
I'm not sure what other approaches there are to this.