+ 1

Is there a C++ Equivalent of this Python3 Function?

Is there a C++ Equivalent of this Python3 Function? def times_n(string, n): temp = "" for everychar in string: temp += everychar*n #this part return temp If I tried to do something like that in C++, it will just multiply the ASCII value by n and adding it into temp. So, how can I do that in C++? Thanks in advance!

30th May 2019, 12:36 PM
Noverdi Ramadhan
Noverdi Ramadhan - avatar
2 odpowiedzi
+ 5
You can create a string of a multiplied char with a specific constructor: string(5, '*'); will produce *****.
30th May 2019, 1:22 PM
HonFu
HonFu - avatar
+ 2
Thanks for the answer!!
30th May 2019, 2:18 PM
Noverdi Ramadhan
Noverdi Ramadhan - avatar