Last active
August 29, 2015 14:08
-
-
Save DTSCode/44fed89afea3ec57ad30 to your computer and use it in GitHub Desktop.
Various C++ Codes
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 <ostream> | |
#include <string> | |
namespace dts { | |
void whisper(std::ostream &out, std::string msg) { | |
for(char &next : msg) { | |
out << ((next >= 'A' && next <= 'Z') ? (next - ('Z' - 'z')) : next); | |
} | |
} | |
void shout(std::ostream &out, std::string msg) { | |
for(char &next : msg) { | |
out << ((next >= 'a' && next <= 'z') ? (next + ('Z' - 'z')) : next); | |
} | |
} | |
} |
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 <string> | |
std::string operator*(std::string raw, int mult) { | |
return --mult != 0 ? raw + raw * mult : raw; | |
} | |
// can now use like this: std::string("foo") * 5, which produces "foofoofoofoofoo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment