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 !
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 !
Do not make direct eye contact with me.
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 !
Do not make direct eye contact with me.
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
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared