Convert string to Uppercase

Feb 5, 2012 at 7:51am
So I do know about toupper function and using it as a loop to convert the a lowercase string into uppercase. However, this is not what I require for my program.


What I need is somewhat having the caps lock turned on, but only for my application. Other programs would not be affected.

Is this possible in C++? By the way, I am making a game kinda like super text twist, and it is only a console application.

Last edited on Feb 5, 2012 at 7:52am
Feb 5, 2012 at 7:58am
It sounds like you would benefit from using a non-buffered input mode.

Check out NCurses and PDCurses.

Good luck!
Feb 5, 2012 at 8:22am
isn't there a more basic approach to the problem?
Feb 5, 2012 at 10:01am
Write a customized ucase_char_traits<char> class.
http://en.cppreference.com/w/cpp/string/char_traits

The simple way would be to inherit from std::char_traits<char> and implement the overloads of assign(), and to_char_type() converting lower case chars to upper case.

Then, typedef std::basic_string< char, ucase_char_traits<char> > ucase_string ;

For good measure, implement the stream insertion and extraction operators as well as getline() for ucase_string.

Implement ucase_string == std::string etc as required.

Use ucase_string in place of std::string. It's a reusable solution, and an overkill for a one-off case.

Note: This would give the equivalent of the caps lock turned on for everything other than characters echoed on a terminal are concerned.
Feb 5, 2012 at 10:47am
thanks jlborges. i will study your suggestion, I'm just starting to learn c++ so it may take a while.
Feb 5, 2012 at 10:54am
> I'm just starting to learn c++ so it may take a while.

Perhaps you should put this on the back burner for now. There are a lot many other things that you should be learning first.
Feb 5, 2012 at 11:05am
>Perhaps you should put this on the back burner for now. There are a lot many other things that you should be learning first.


Yeah, I still have a lot to learn. But thanks anyway, at least I now have an idea on how to do that:)
Feb 5, 2012 at 11:31pm
If you are looking to make sure all user input in an interactive console UI program is uppercase, don't bother messing with locales. Just convert it to uppercase in your input handler -- that is, wherever you get input.
Topic archived. No new replies allowed.