What is the equivalent of toupper, strcpy and strtok in C++ ?
Printable View
What is the equivalent of toupper, strcpy and strtok in C++ ?
toupper, strcpy and strtok.Quote:
Originally posted by Max
What is the equivalent of toupper, strcpy and strtok in C++ ?
Quzah.
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.
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:Quote:
Originally posted by Eibro
i'm not aware of any toupper() in the std::string type.
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';
}
if you use MSVC
CharUpper()
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.Quote:
Originally posted by face_master
I couldn't find any toupper()/tolower() func so so I just wrote my own :) works fine for me
Explain¿Quote:
Originally posted by moi
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 ;)Quote:
the words of a true noob.
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.Quote:
Originally posted by face_master
I couldn't find any toupper()/tolower() func so so I just wrote my own :) works fine for me
>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 :rolleyes:. 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