Created
November 4, 2018 23:19
-
-
Save dlandahl/c1e7ff16dcbdee5e07ae6af8091d6b48 to your computer and use it in GitHub Desktop.
Repeat a string with multiplication operator
This file contains 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 lhs, int rhs) | |
{ | |
std::string instance = lhs; | |
for (unsigned n = 1; n < abs(rhs); n++) | |
lhs.append(instance); | |
return lhs; | |
} | |
int main() | |
{ | |
using namespace std::string_literals; | |
std::cout << "some text"s * 4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment