std::string?
As we know the C++ is one of the old languages (officialy renamed from C with classes to C++ and released
during 1983).
During all this year this language has been matured very much.
But still within all this, this language does not have a simple std::string::tolower() or
std::string::toupper() methods for string manuplation.
I mean even C <string.h> have a char *strlwr(char *str) and
char *strupr(char *str) function, now I know what you are gonna say that.
Why don't you just take astd::stringand use the.c_str()method and usestrlwrorstrupron it.
.c_str() is a const char*, that means
you can't mutate the value of the string, sure you can use strcpy and copy the value to another
variable,
but it will only cause extra overhead.
tolower(char c)std::transform from <algorithm> library to change the case of
the string in one go
#include <algorithm>
int main() {
std::string sampleLower("this is a lower string");
std::transform(sampleLower.begin(), sampleLower.end(), sampleLower.begin(), toupper);
return 0;
}
This will output:
$ THIS IS A LOWER STRING
The transform takes 4 parameters
toupper or
tolower
std::wstring for the extra wide enicodes such as é or
á, etc.
str.lower() or
str.upper() methods which makes the work easy, but still, C++ is a go to language for writing fast
performant systems code.