Problem with stringstream
Aug 14, 2012 at 6:10pm UTC
I'm trying to add a FPS counter to my game. Now the problem is that SFML only prints std::strings, so I'm trying to convert the fps value (an int) to string using stringstream.
Here's the code:
1 2 3 4 5 6
// fps calculation
ticktime = rendertick.getElapsedTime();
fps = 1000000 / ticktime.asMicroseconds();
ss << fps;
temp = "FPS: " + ss.str();
fpstext.setString (temp);
Apparently there's something wrong with it, because it outputs thousands of numbers. What am I doing wrong here?
EDIT: Solved it. I noticed that the amount of numbers was increasing, so I decided to clear ss with this:
1 2
ss.clear();
ss.str (std::string());
And now it works perfectly!
Last edited on Aug 14, 2012 at 6:20pm UTC
Topic archived. No new replies allowed.