Sign in to follow this  
rgibson11

variables in a string

Recommended Posts

Hello, I am having some problems with displaying a font on a screen, I am using opengl with OGLFT library which uses freetype font system. It displays const char * values like "Hello" perfectly, but I need it to display for example the fps, like this FPS : (float variable here) I looked for ways to transfer numbers to strings but no luck. stringstream doesn't seem to work either. if anyone please could give me some info if you ran into this problem before, thanks,

Share this post


Link to post
Share on other sites
std::stringstream ss;
std::string s;

ss << fps;
ss >> s;

yourfunction( s.c_str() );
or if you're lazy
yourfunction( ss.str().c_str() );
or if you're very lazy
yourfunction( boost::lexical_cast<whateveryouwant>( fps ) );

Share this post


Link to post
Share on other sites
Thanks a lot Rewdew, that solved it!
I have no idea but I was doing things very similar to your code but it just wasn't showing up. I guess its just due to me being fairly new to stringstreams

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this