SFML community forums
Help => Graphics => Topic started by: ravenheart on September 16, 2008, 12:35:31 am
-
now i want my programm to show the time it is running
i did it something like
main()
{
String Text;
Text.SetFont(sf::Font::GetDefaultFont());
Text.SetSize(20);
Clock Timer;
while running
{
events
{
}
Text.SetText(Timer.GetEclapsedTime(); converted to string
Draw Text;
}
}
now i dont want endless strings one after one , i only want ONE text to be shown, showing the current runnig-time
whats my mistake?
-
oh oh , after thinking bout it i believe i found the answer, with my conversion
osstream out;
out << blablabla;
string str = out.str();
the string gets longer and longer becasue of out << ,...
well thats not a sfml problem anymore but there was something with ios:flags as solution
-
2 mins of googling and i found what i was looking for^^
( i´m glad i remember anything since the days i learnd c++ =)
out << seekp(0);
was all i needed to add
sry for spamming
-
2 mins of googling and i found what i was looking for^^
( i´m glad i remember anything since the days i learnd c++ =)
out << seekp(0);
was all i needed to add
sry for spamming
that shouldn't be necessary ... this is the function i use and it has worked well for quite some time :)
template<class T>
std::string ToString(T val)
{
std::stringstream ss;
ss << val;
return ss.str();
}
you can also go the C way
char buf[64];
sprintf(buf, "%d%, val);
but then you need to watch out for buffer overruns and keeping track of what type val actually is .. so the stringstream version is definitely recommended :)