- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Concatenate a string given number of times in C++ programming
A program to concatenate a string a given number of times will run the string concatenate method n number of times based on the value of n.
The result would be string repeated a number of times.
Example
given string: “ I love Tutorials point” n = 5
Output
I love Tutorials pointI love Tutorials pointI love Tutorials pointI love Tutorials point I love Tutorials point
After seeing the output, it is clear that what the function will do.
Example
#include <iostream> #include <string> using namespace std; string repeat(string s, int n) { string s1 = s; for (int i=1; i<n;i++) s += s1; // Concatinating strings return s; } // Driver code int main() { string s = "I love tutorials point"; int n = 4; string s1 = s; for (int i=1; i<n;i++) s += s1; cout << s << endl;; return 0; }
Output
I love tutorials pointI love tutorials pointI love tutorials pointI love tutorials point
- Related Articles
- C++ program to concatenate a string given number of times?
- How to return a string repeated N number of times in C#?
- Number of times a string appears in another JavaScript
- Maximum number of removals of given subsequence from a string in C++
- Check if a given string is a valid number in C++
- XOR of numbers that appeared even number of times in given Range in C++
- C++ code to count number of times stones can be given
- C++ Program to Find the Number of Permutations of a Given String
- Count of number of given string in 2D character array in C++
- Superperfect Number in C programming
- How to concatenate a std::string and an int in C++?
- Concatenate null to a string in Java
- C/C++ Programming to Count trailing zeroes in factorial of a number?
- How to replicate a string for a specified number of times in MySQL?
- How to repeat a string for a specified number of times in Golang?

Advertisements