You can see ASCII table letters are just numbers for the computer.For example you can get a number from a letter
5='0'-'5';
And answer for your question is yes,it is possible
You cann create class String that has string in it and if the user inputs space in string ,you can make it throw exeption or to just connect characters without spaces.
When you read a string with >> it normally ignores spaces. For a case-insensitive compare, you can do something like this. Test it with yes, YES, yEs, etc. Also try with spaces in front and/or after (which the >> should ignore).
another way is to pre-process the input, if that is acceptable:
string s;
cin >> s;
s.erase(std::remove(s.begin(), s.end(), ' '), s.end()); //removes ALL spaces from the string.
//you don't really need to remove spaces with cin >> but you may if you choose to use getline.
//uppercase the string:
std::transform(s.begin(), s.end(),s.begin(), ::toupper);
now you can compare it or whatever else:
if(s == "YES"s) //the s is required to use == ( s is NOT the variable name, in hindsight string s was poor for the example, here s is just making the constant text a string)
{
}
@jonin, That's some nifty usage of <algorithm>. But you don't need the string literal operator on "YES" if one of the operands is a std::string. Also, it should be mentioned that using ""s requires C++14 and using namespace std::string_literals.
it seems likely mine was using the C version, actually...
looking at it now.
the cctype one is failing due to template syntax. So its not using that one.
and its not using standard one.
and locale one has an extra parameter, so its not using that one.
so I am nearly convinced its using the C function.
to use std:: you may have to wrap it in a lambda, that should work.