Menu
Coddy logo textTech

Repeat a String

Lesson 2 of 18 in Coddy's Functions in C++: Building Your Own Functions course.

challenge icon

Challenge

Easy

Write a function to repeat a string a given number of times with a specific separator.


The repeat_string function is a function that takes a string and repeats it a specified number of times with a specific separator in between each repetition.


For example, if the string is "Coddy", the number of repetitions is 3, and the separator is "@", the result will be:

Coddy@Coddy@Coddy

Set the default number of repetitions to 2 and the separator to "$". So, by default, if the string is "Coddy", the result will be:

Coddy@Coddy

Try it yourself

#include <iostream>
using namespace std;

string repeat() {
    
    

}

All lessons in Functions in C++: Building Your Own Functions