Thread: Manipulating Input

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    36

    Manipulating Input

    I want to write a program in which the user enters a string and the program converts the input into uppercase.
    For example, say the user enters "January" and i store it into a string type variable, how do I change it into "JANUARY"?

  2. #2
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    Loop over each character of the string and call toupper on it:
    Code:
    #include <cctype>
    #include <string>
    
    using std::string;
    using std::toupper;
    
    for (string::size_type i = 0; i < str.length(); i++)
      str[i] = toupper(str[i]);
    Kampai!

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    36
    I am a beginner( newbie) and I have no idea what that program does. Can u explain it to me?

  4. #4
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    It would help to see what code you have already so that I can help you write something a bit simpler. If you're a beginner than I don't imagine you're using C++ string objects.
    Kampai!

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. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 03:54 AM
  3. I would love some input on my BST tree.
    By StevenGarcia in forum C++ Programming
    Replies: 4
    Last Post: 01-15-2007, 01:22 AM
  4. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM