Skip to content

Instantly share code, notes, and snippets.

@DTSCode
Last active August 29, 2015 14:08
Show Gist options
  • Save DTSCode/44fed89afea3ec57ad30 to your computer and use it in GitHub Desktop.
Save DTSCode/44fed89afea3ec57ad30 to your computer and use it in GitHub Desktop.
Various C++ Codes
#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);
}
}
}
#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