Skip to main content
GameDev.net gamedev.net
🔒 Locked

variables in a string

Started by rgibson11 Mar 16, 2009 at 6:25 AM 3 replies 1.1k views
Original Post
rgibson11
rgibson11
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,
Rewdew
Rewdew
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 ) );
swiftcoder
swiftcoder
Quote:
Original post by rgibson11
I looked for ways to transfer numbers to strings but no luck. stringstream doesn't seem to work either.
In what way does stringstream not work? It is the accepted way of performing this operation.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
rgibson11
rgibson11
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
_Sigma
_Sigma
boost::lexical_cast is quite useful for these types of problems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.