cryfreq
cryfreq

Reputation: 13

FPS Counter in the window title GLFW

I'm trying to get my Frames-Per-Second readout to appear in my window title. I have done it once before, but how would I set up the code to do that? I need to switch from float to const char *.

Upvotes: 1

Views: 1293

Answers (2)

Rosme
Rosme

Reputation: 1049

A simple way to do, and making it compatible with every numerical could be that:

#include <sstream>

template<class T>
char* toChar(T t) {
    std::ostringstream oss;
    oss << t;
    return oss.str().c_str();
}

This way, no matter if you use int, float, long or whatever else, it will work and return it as a char* string.

Upvotes: 2

zeller
zeller

Reputation: 4974

You can use an istringstream then str() then c_str().

Upvotes: 1

Related Questions