Thread: about toupper()

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    9

    about toupper()

    Hello, I'm wondering if there is a library with a toupper() kind of function that can handle string insted of char?

    Code:
    #include <iostream>
    #include <ctype.h>
    using namespace std;
    
    void toUpperCase(char*);
    
    int main() {
        char str[80];
        
        cout << "Enter something: "; 
        cin.getline(str, 80);
        
        toUpperCase(str);
        
        cin.get();
        return 0;
    }
    
    
    void toUpperCase(char* s) {
        int count;
        while(*s) {
            *s = toupper(*s);
            s++;
            count++;
        }
        s -= count;
        cout << s;
    }
    this is what I've got now, but I want to use string instead

    as I remember it I could use ASCI values of the upper case letters to convert, but that's sounds tiresome. Why reinvent something that maybe already exists, right?
    Last edited by mkeisu; 09-09-2009 at 03:36 PM.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Indeed there is: boost string algorithms which includes algorithms for case conversion.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    std::transform() for a one liner conversion.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    9
    Thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. toupper() function
    By strokebow in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2008, 10:54 AM
  2. need example of toupper()
    By Waldo2k2 in forum C++ Programming
    Replies: 8
    Last Post: 06-29-2002, 10:07 AM
  3. conio.h, toupper(), and a craps game
    By loki221 in forum C Programming
    Replies: 2
    Last Post: 11-28-2001, 07:40 PM
  4. Help Converting a String to uppercase using TOUPPER()
    By frgmstr in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2001, 01:56 PM
  5. implicit declatation of function 'int toupper(...)'
    By Intimd8r in forum C Programming
    Replies: 3
    Last Post: 10-01-2001, 02:43 PM