Is there a function like this:
nofv(int i, char c)
That returns a string of i c's? Such as this:
nofv(5, "m")
Would return a string of "mmmmm"? Or will I have to make my own? Thanks :D !
Printable View
Is there a function like this:
nofv(int i, char c)
That returns a string of i c's? Such as this:
nofv(5, "m")
Would return a string of "mmmmm"? Or will I have to make my own? Thanks :D !
Since this is the C++ board, I'm assuming that STL solutions are acceptable. If that's the case, then a std::string constructor will do exactly what you want:
Code:std::string str(5, 'm');
std::cout << str << std::endl;
/* output: mmmmm */
Well, I'm not too excited to use strings (I like them, just char arrays would work better in my case). Thanks anyway :D !
Code:#include <iomanip.h>
int main() {
cout << setw(6) << setfill('m') << endl;
return 0;
}
You would have to pass the array you want to store it in, otherwise you return a pointer to a temporary object...It would be easy to write a function like that, but I think you could just use the memset function