Piece of cake if you're using the standard string class:
Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string a = "This is a test";
string b = "Test";
string c;
while (c.size() < a.size())
c += b;
c.resize(a.size());
cout << a << '\n' << c << '\n';
return 0;
}
It's not so easy with array based strings, but still not bad, you'd have to do it manually:
Code:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a[] = "This is a test";
char b[] = "Test";
size_t alen = strlen(a);
size_t blen = strlen(b);
char *c = new char[alen + 1];
*c = '\0';
while (strlen(c) < alen - blen)
strcat(c, b);
strncat(c, b, alen - strlen(c));
cout << a << '\n' << c << '\n';
return 0;
}
No biggie, but it's harder to get right than the first one.