Last active
August 29, 2015 14:01
-
-
Save Experiment5X/fffc3f37b4c8a2edf479 to your computer and use it in GitHub Desktop.
Python-like string multiplication... probably not a good idea to actually use though.
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> | |
std::string operator *(std::string str, int n) | |
{ | |
std::string toReturn = ""; | |
if (n <= 0) | |
return toReturn; | |
for (int i = 0; i < n; i++) | |
toReturn += str; | |
return toReturn; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
std::cout << std::string("Adam") * 5 << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment