#1
  1. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511

    combine cin >> and toupper()


    Let's say I do something like this:

    cin >> cRollType;
    cRollType=toupper(cRollType);

    Can I combine those into one statement somehow? I've thought of
    cRollType=toupper(cin >> cRollType);

    but that won't work because cin >> won't return a char.
    cRollType=toupper(cin.getch());
    would work, but then I'd still need another line to clear the buffer afterwards.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    244
    I am no great shakes at C++ IO, but is this useful to you?

    Code:
    #include <ctype.h>
    #include <stdio.h>
    
    int cin2upper(FILE *fin){
        int tmp = getc(fin);
        if (isalpha((char)tmp))
            tmp = toupper(tmp);
        return tmp;
    }
    
    int main(){
        int tmp;
    
        while ((tmp = cin2upper(stdin)) != EOF){
            putc(tmp, stdout);
        }
    
        return 0;
    }

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    figure out what it is cin returns, and compare that to the argument of toupper(). if cin returns a character cast to an integer it could work.
  6. #4
  7. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511
    cin returns an istream object, so that's out. I could use a function, but that would really defeat the purpose. The program that gave me the idea to try this only uses it twice, and I'm really only doing it to see if I can.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn

IMN logo majestic logo threadwatch logo seochat tools logo