Thread: out putting upper case letters

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    22

    out putting upper case letters

    Can anyone help me figure out what im doing wrong? I want to input a string of characters, or better yet, multiple lines of strings, and out put them as capital letters. What i have so far will allow you to input a string but it only outputs the 1st letter.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        int i;
        char a;
        string str;
        cout << "Enter a string of characters to convert to uppercase: ";
     
        for (i = 0; i < 100; i++)
        {
        cin >> str;
        cout << (char)(toupper(str.at(a)));
        }  
    
    
        return 0;    
    }

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    First, 'a' is uninitialized, but you are using it as an index. My compiler warns me about this - if yours does not, adjust its warning settings until it does, then fix any and all warnings it gives you.

    Second, you probably want 'str.at(i)' and to only run while 'i < str.length()'.
    Programming and other random guff: cat /dev/thoughts > blogspot.com (previously prognix.blogspot.com)

    ~~~

    "The largest-scale pattern in the history of Unix is this: when and where Unix has adhered most closely to open-source practices, it has prospered. Attempts to proprietarize it have invariably resulted in stagnation and decline."

    Eric Raymond, The Art of Unix Programming

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    22
    Which compiler do you use? When i make those changes ^ it doesnt allow me to input anything.

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    22
    HAHAHA just kidding. I got it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-11-2011, 05:52 PM
  2. Replies: 6
    Last Post: 03-07-2011, 02:15 PM
  3. Remove upper case letters from a char string
    By lavinpj1 in forum C Programming
    Replies: 8
    Last Post: 05-01-2006, 12:09 PM
  4. upper case to lower case problem
    By Jasonymk in forum C++ Programming
    Replies: 3
    Last Post: 04-27-2003, 05:35 AM