Created
October 24, 2016 11:40
-
-
Save illescasDaniel/0e0f0e0094d43797ba82cb8b1ab69ac9 to your computer and use it in GitHub Desktop.
String toUpper & toLower [C++]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| string toUpper(string str); | |
| string toLower(string str); | |
| vector<string> toUpper(vector<string> strings); | |
| vector<string> toLower(vector<string> strings); | |
| int main(int argc, char *argv[]) { | |
| string hello = "Hello World"; | |
| hello = toUpper(hello); | |
| cout << hello << endl; | |
| cout << toUpper("hi girl") << endl; | |
| cout << toLower("HI how are YOU?") << endl; | |
| vector<string> names = {"daniel", "sofia", "noel"}; | |
| names = toUpper(names); | |
| for (auto str: toUpper(names)) { | |
| cout << str << ' '; | |
| } | |
| return 0; | |
| } | |
| string toUpper(string str) { | |
| transform(str.begin(), str.end(), str.begin(), ::toupper); | |
| return str; | |
| } | |
| string toLower(string str) { | |
| transform(str.begin(), str.end(), str.begin(), ::tolower); | |
| return str; | |
| } | |
| vector<string> toUpper(vector<string> strings) { | |
| for_each(strings.begin(), strings.end(), [](string& str){ str = toUpper(str); }); | |
| return strings; | |
| } | |
| vector<string> toLower(vector<string> strings) { | |
| for_each(strings.begin(), strings.end(), [](string& str){ str = toLower(str); }); | |
| return strings; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment