Web Analytics Made Easy -
StatCounter uppercase method - CodingForum

Announcement

Collapse
No announcement yet.

uppercase method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • uppercase method

    I'm using the g++ c++ compiler, and I need a method to convert a string to all uppercase characters. the string class doesn't seem to contain one, at least, not one that I've been able to find. please help!

  • #2
    One method I use:
    Code:
    #include <algorithm>
    #include <string>
    using namespace std;
    int main()
    {
     string s="hello";
     transform(s.begin(), s.end(), s.begin(), (int(*)(int)) toupper);
    }
    Another way of doing it is like this:
    Code:
    #include <string>
    using namespace std;
    int main()
    {
     string s="hello";
     for (int j=0; j<s.length(); ++j)
     {
      s[j]=toupper(s[j]);
     }
    }
    HTH,
    -sage-
    Last edited by sage45; Aug 1, 2005, 10:46 PM.
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

    Comment


    • #3
      fair enough, I thank you

      but where (what header) does the function toupper come from?

      Comment


      • #4
        I think it is in iomanip but I could be wrong.
        OracleGuy

        Comment


        • #5
          toupper is actually in the STDLIB or CTYPE headers...

          -sage-
          HTML & CSS Forum Moderator

          "If you don't know what you think you know, then what do you know."
          R.I.P. Derrick Thomas #58
          1/1/1967 - 2/8/2000

          Comment

          Working...
          X