Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- int main(){
- std::string text = "The QuiCk BroWN FOX"; /// Some string
- for(int i = 0; i < text.size(); i++){ /// for loop that takes string.size() and for each iteration
- text[i] = tolower(text[i]); /// will get the current letter at index i inside the string text
- } /// and replace it with the same letter in lowercase
- std::cout << text << std::endl; ///print in lowercase
- for (char& letter : text){ /// The same can be done with foreach loop (since C++11)
- letter = toupper(letter); /// in this example we are changing the text to uppercase
- } /// char& letter -> is used in order to take the letter by refrence
- /// which means by address in the memory so it will be
- /// changed if we don't take it like that we will change a copy
- std::cout << text << std::endl; /// Prints the text in uppercase
- /// There are many more ways to do that check on google.com!
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment