Thread: c to c++

  1. #1
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110

    c to c++

    What is the equivalent of toupper, strcpy and strtok in C++ ?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: c to c++

    Originally posted by Max
    What is the equivalent of toupper, strcpy and strtok in C++ ?
    toupper, strcpy and strtok.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    std::string::find() would be functionally equivalent to strtok()
    and the assignment operators, constructors of the std::string class take care of strcpy.

    i'm not aware of any toupper() in the std::string type.

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Originally posted by Eibro
    i'm not aware of any toupper() in the std::string type.
    There is no toupper in the std::string type. You can use the toupper in cctype (ctype.h). In stead of a for loop you can use the transform function in algorithm:
    Code:
    #include <string>
    #include <cctype>
    #include <algorithm>
    #include <iostream>
    
    int main(void)
    {
       std::string msg = "Hello world";
       std::transform(msg.begin(), msg.end(), msg.begin(), toupper);
       std::cout << msg << '\n';
    }

  5. #5
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    if you use MSVC
    CharUpper()
    PHP and XML
    Let's talk about SAX

  6. #6
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    I couldn't find any toupper()/tolower() func so so I just wrote my own works fine for me

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by face_master
    I couldn't find any toupper()/tolower() func so so I just wrote my own works fine for me
    the words of a true noob.
    hello, internet!

  8. #8
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    Originally posted by moi
    the words of a true noob.
    Explain¿

  9. #9
    Registered User fry's Avatar
    Join Date
    Mar 2002
    Posts
    128
    the words of a true noob.
    Noobs dont often write their own functions. They dont know how Besides, you learn a lot more that way too
    IDE: Dev C++ 5
    Lib: Allegro
    OS: Windows 2000

  10. #10
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by face_master
    I couldn't find any toupper()/tolower() func so so I just wrote my own works fine for me
    I'm with you, face_master. I have more fun writing my own function anyway. I've done my own isdigit, atoi, and strlen functions. I don't really like using library functions because I don't know how those functions work. That's one thing I don't like about data encapsulation——being kept in the dark about how everything works.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >That's one thing I don't like about data encapsulation——being kept in the dark about how everything works.
    That's the reason for encapsulation . But you can find implementations of the standard C library if you expend a small amount of energy looking.

    >I couldn't find any toupper()/tolower() func
    Try <cctype> or <ctype.h>. If they're not there then your compiler has issues.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed