[Solved] A function to print copies of a character [closed]


“How to write a function which gets a character and the number of copies as function arguments?”

As mentioned, you can implement your printSplitter() function simply as

std::string printSplitter (int N, char C) {
    return std::string(N,C);
}

See the reference documentation of std::string constructor‘s (2).


So you probably want to have something simple like this (no need for implementing your own printSplitter(), at least I see no benefit of doing so):

int main() {
    std::cout << std::string(10, '-') << std::endl; // prints: ----------
    return 0;
}

Or even simpler

int main() {
    std::cout << "----------" << std::endl;
    return 0;
}

solved A function to print copies of a character [closed]