How we can convert a multi language string or unicode string to upper/lower case in C or C++.
Set the locale first, example :
setlocale(LC_ALL, "German")); /*This won't work as per comments below */
setlocale(LC_ALL, "English"));
setlocale( LC_MONETARY, "French" );
setlocale( LC_ALL, "" ); //default locale
Then use
std::use_facet std::locale as follows:-
typedef std::string::value_type char_t;
char_t upcase( char_t ch )
{
return std::use_facet< std::ctype< char_t > >( std::locale() ).toupper( ch );
}
std::string toupper( const std::string &src )
{
std::string result;
std::transform( src.begin(), src.end(), std::back_inserter( result ), upcase );
return result;
}
const std::string src = "Hello World!";
std::cout << toupper( src );