How do I ignore the case of something that I am inputting?

I have tried tolower() and toupper(), but these don't seem to work on the string I am using.

I am inputting a word using: cin >> answer;

This input can be either upper or lower case. In the end I want to ignore the overall case of this input to run through an if() statement, without having to program the possibilities.

Any ideas?

(I am using CodeBlocks v12.11)
Last edited on
1
2
3
4
5
6
7
8
string strtoupper(string in)
{
        for(unsigned int i = 0; i < in.size(); i++)
        {
               in[i] = toupper(in[i]);
        }
        return in;
}



I hope this helps! Substitute upper with lower for opposite results.
I had to do the exact same thing.
Thanks.
Or you could use google and get a more correct solution:
http://stackoverflow.com/a/313990/1959975

Seriously, before writing your own solution see if someone already wrote one that's better. I'm not trying to be mean to Superdude, by the way, this is just something often overlooked.
Last edited on
Topic archived. No new replies allowed.