Last active
July 19, 2019 18:35
-
-
Save FlintSable/4f683aefd55c2db3c659e267cadc95cc to your computer and use it in GitHub Desktop.
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
| :: compile and rename to hello | |
| g++ hello.cpp -o hello | |
| g++ -Wall -std=c++14 hello.cpp -o hello | |
| :: execute the compiled code | |
| ./hello |
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 <string> | |
| using namespace std; | |
| // found=str.find("haystack"); | |
| // if (found != string::npos) | |
| // std::cout << "'haystack' also found at: " << found << '\n'; | |
| int main() { | |
| string userLine; | |
| string t1 = "I don't know"; | |
| string t2 = "talk to you later"; | |
| string t3 = "just kidding"; | |
| string t4 = "best friend forever"; | |
| string t5 = "too much information"; | |
| size_t pos; | |
| cout << "Enter text:\n"; | |
| getline(cin, userLine); | |
| cout << "You entered: " << userLine << "\n"; | |
| while((pos = userLine.find("IDK")) != string::npos){ | |
| userLine.replace(pos, 3, t1); | |
| } | |
| if((pos = userLine.find("BFF")) != string::npos){ | |
| userLine.replace(pos, 3, t4); | |
| } | |
| while((pos = userLine.find("JK")) != string::npos){ | |
| userLine.replace(pos, 2, t3); | |
| } | |
| while((pos = userLine.find("TMI")) != string::npos){ | |
| userLine.replace(pos, 3, t5); | |
| } | |
| while((pos = userLine.find("TTYL")) != string::npos){ | |
| userLine.replace(pos, 4, t2); | |
| } | |
| cout << "Expanded: "<< userLine << "\n"; | |
| return 0; | |
| } | |
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> | |
| using namespace std; | |
| int main() | |
| { | |
| int dog_age = 3; | |
| int early_years, later_years, human_years; | |
| early_years = 21; | |
| later_years = (dog_age - 2) * 4; | |
| human_years = early_years + later_years; | |
| cout << "My name is Sparkles! Ruff Ruff, I am " << human_years << " years old in human years.\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment