1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <cctype> // pour tolower et toupper
#include <string> // pour string
#include <iostream> // pour cout
#include <algorithm> // pour transform
struct my_tolower
{
char operator()(char c) const
{
return std::tolower(static_cast<unsigned char>(c));
}
};
struct my_toupper
{
char operator()(char c) const
{
return std::toupper(static_cast<unsigned char>(c));
}
};
int main()
{
std::string s("ABCDEF");
std::transform(s.begin(), s.end(), s.begin(), my_tolower());
std::cout << s; // affiche "abcdef"
std::transform(s.begin(), s.end(), s.begin(), my_toupper());
std::cout << s; // affiche "ABCDEF"
return 0;
} |