Skip to content

Instantly share code, notes, and snippets.

@Experiment5X
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Experiment5X/fffc3f37b4c8a2edf479 to your computer and use it in GitHub Desktop.
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.
#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