Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Created February 23, 2022 15:54
Show Gist options
  • Save lyf-is-coding/db4c44a4a69f0b8dedb3da6e8d6932fa to your computer and use it in GitHub Desktop.
Save lyf-is-coding/db4c44a4a69f0b8dedb3da6e8d6932fa to your computer and use it in GitHub Desktop.
C++ STL Uppercase/ Lowercase string
// Input : abHDbGd
// Output : ABHDBGD - abhdbgd
#include <string>
std::string UppercaseStr(std::string str)
{
int str_length = str.length();
for (int i = 0; i < str_length; ++i)
str[i] = std::toupper(str[i]);
return str;
}
std::string LowercaseStr(std::string str)
{
int str_length = str.length();
for (int i = 0; i < str_length; ++i)
str[i] = std::tolower(str[i]);
return str;
}
std::cout << UppercaseStr("abHDbGd"); // ABHDBGD
std::cout << LowercaseStr("abHDbGd"); // abhdbgd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment