To repeat a string...
...i used this code:
string MFUNC::strrepeat (string str, int repeat)
{
//repeats a single string number of times
string strrepeated;
int rep = 0;
while (rep < Number)
{
strrepeated = strrepeated + Character;
rep = rep + 1;
}
return strrepeated;
}
This works perfectly fine, but i think it''s a bit too slow. I can actually see string sliding when i use cout << Mfunc.strrepeat("X",80). Now i''m asking if there''s any other function in any library that does the same, but little faster?
Thanks for answers.
The sliding effect is in
To make the function a bit faster you could use the
HTTP 500 strike 1
EDIT1: Added suggestion.
Update GameDev.net system time campaign:
[edited by - dalleboy on January 3, 2003 4:12:08 PM]
cout
as the string
is already returned from the function before it is send to cout
. A long string
takes a long time to output... To make the function a bit faster you could use the
append
member function and preallocating the string
using the reserve
member function.HTTP 500 strike 1
EDIT1: Added suggestion.
Update GameDev.net system time campaign:
'date ddmmHHMMYYYY'
[edited by - dalleboy on January 3, 2003 4:12:08 PM]
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement