Results 1 to 6 of 6

Thread: String to Uppercase

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    String to Uppercase

    How can I make sure a <string> is in all uppercase? I've found ways for char strings, but not <string> strings.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    is there any way to make them all uppercase?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    twanvl, you deleted your post.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    Code:
    #include <algorithm>
    #include <string>
    #include <locale>
    #include <functional>
    //...
    std::string s;
    if (std::find_if(s.begin(),s.end(),std::bind2nd(std::islower<char>,std::locale::clasic()))==s.end())
        // all uppercase
    else
        // some lowercase
    This should work

    twanvl, you deleted your post.
    Sorry, I found a mistake in my code.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    #include <algorithm>
    #include <string>
    #include <iostream>
    #include <cctype>
    
    using namespace std;
    
    int main() {
        string s = "Hello world!";
        transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper);
        cout << s << endl;
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks, dudes.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width