Skip to content

Instantly share code, notes, and snippets.

@dlandahl
Created November 4, 2018 23:19
Show Gist options
  • Save dlandahl/c1e7ff16dcbdee5e07ae6af8091d6b48 to your computer and use it in GitHub Desktop.
Save dlandahl/c1e7ff16dcbdee5e07ae6af8091d6b48 to your computer and use it in GitHub Desktop.
Repeat a string with multiplication operator
#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