Thread: setting all input to caps

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    Question setting all input to caps

    hello, I hope that one of you could help me out a bit: is there a way to, right from the start of the program, to set all inputed character values to be transfer to only CAPS or only lower case.

    This is what I've found out:

    #include <ctype>

    char c

    cout << "input a letter ";
    cin >> c ;
    c = toupper(c);

    this works and is not too bad, as my program is a constant loop that finishes when the game is over, but I am looking for an easier way out, thanks in advance,

    axon

  2. #2
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    I can't test it where I am, and I really have no idea if this will work or not, but can you set flags for cin like you do for cout?

    Like you'd set
    cout.setf (ios_base::uppercase);
    to do output in uppercase
    how about
    cin.setf (ios_base::uppercase);
    Demonographic rhinology is not the only possible outcome, but why take the chance

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i found in CS class yesterday, that (at least in .NET), you don't need to include ctype if u use

    <iostream>

    using namespace std;

    in your program as opposed to

    <iostream.h>

    Don't know why it works, but it does.

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>Don't know why it works, but it does.
    Some compilers do that for convenience, but it's not standard across compilers so you shouldn't rely on it :-)
    *Cela*

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i figured it was a .net thing, but without the short iostream and namespace declaration it won't work less u use ctype.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. input redirection
    By sashaKap in forum C Programming
    Replies: 6
    Last Post: 06-25-2009, 01:59 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Structure and Linked List User Input Question
    By kevndale79 in forum C Programming
    Replies: 16
    Last Post: 10-05-2006, 11:09 AM
  5. Custom Made Safe Input Function
    By Beast() in forum C Programming
    Replies: 6
    Last Post: 08-21-2004, 10:19 PM