   ToLowerCase and ToUpperCase in C++
  is it possible if i implement tolowercase or touppercase  into string instead of char array in c++?because i found it is only possible for the char array....thanks before :)   
  Use std::transform to modify the string in-place.   ;  Example:string str="ewrwerqweqwe";std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) toupper);include <cctype> for toupper and <algorithm> for the transform function.   ;  Hi Personal Worker,There is no native toupper/tolower function for the string class in the Standard C++ Library per se. But actually it is very easy to convert from char array to string. One of the string constructor takes in char array.You can define a function that uses the C Library function toupper/tolower to convert string character by character, then returns the converted char array as a string.#include <string>#include <cctype>using std::string;using std::tolower;using std::toupper;string FN_ToUpper(const string& s){  string str(s);  for(size_t i = 0; i < str.length(); ++i)    str = toupper(str);  return str;}string FN_ToLower(const string& s){  string str(s);  for(size_t i = 0; i < str.length(); ++i)    str = tolower(str);  return str;}Hope that helps.Joshua;  thanks for the reply friends...now, i am trying to implement suggestion above in my program...thanks...   ;Quote:string FN_ToUpper(const string& s){  string str(s);  for(size_t i = 0; i < str.length(); ++i)    str = toupper(str);  return str;}bro, you said that we passed in the char array into the constructor but what i see here (in my little opinion) you did pass the reference of the string s?is it?   ;Quote:Original post by passwordExample:string str="ewrwerqweqwe";std::transform(str.begin(), str.end(), str.begin(), (int(*)(int)) toupper);include <cctype> for toupper and <algorithm> for the transform function.this one can work properly, may you help me to explain more detail about transfrom? and what is .begin(), .end(), and also the (int(*)(int)), what is those thing..?thanks   ;  you dont need any casting:std::string value = something;std::transform( value.begin(), value.end(), value.begin(), tolower );works in vc++ 2005 atleast   ;  be careful with these solutions, they don't account for locale/unicode - and hence inherit poor portability. Some languages don't have 1-to-1 transformations between lower case characters and uppercase characters. The solutions provided here will only work on an english/some european based languages.you need to specify an std::locale object with the calls to std::transform, or use a specialised (custom written) implementation of std::locale. Usually a basic instance of std::locale::classic() will surfice.see: http://gcc.gnu.org/onlinedocs/libstdc++/22_locale/howto.html for further details.   ;  Hi Personal_Worker,Sorry, I assumed that the original type that you are tring to convert toupper/tolower is string.Here is the modified code for original type char array:(The only thing changed is the function input argument type. Note that the string class constructor also takes in char array as input argument.)#include <string>#include <cctype>using std::string;using std::tolower;using std::toupper;string FN_ToUpper(char* s){string str(s);for(size_t i = 0; i < str.length(); ++i)str = toupper(str);return str;}string FN_ToLower(char* s){string str(s);for(size_t i = 0; i < str.length(); ++i)str = tolower(str);return str;}To address what Silvermace said, you are partially correct to say that the above does not account for Unicode or locale. But IMHO, it does not matter in this case actually, because for the tolower and toupper functions in the C Standard Library, if there is no corresponding uppercase or lowercase character in the current locale, the functions will simply return the input argument untouched. The program won't crash...If you really need to write Unicode compatible code, then you probably should be using wchar_t, wstring and their associated functions instead.Regards,Joshua