Manipulating Input

This is a discussion on Manipulating Input within the C++ Programming forums, part of the General Programming Boards category; I want to write a program in which the user enters a string and the program converts the input into ...

  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, 02:59 AM
  2. For loop problems, input please.
    By xIcyx in forum C Programming
    Replies: 2
    Last Post: 04-22-2007, 04: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, 04:42 PM
  5. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 04:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21