This topic is now archived and is closed to further replies.


C++: displaying floats

Recommended Posts

In C++:

#include <sstream>
#include <string>


float float_obj = 0.02f;

std::stringstream ss;
ss << float_obj;
std::string float_str;
ss >> float_str;

In C:

#include <stdio.h>


float float_obj = 0.02f;

char float_str[5];
sprint( float_str, "%f", float_obj );

[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || MSVC++ Library Fixes || BarrysWorld || E-Mail Me ]

Share this post

Link to post
Share on other sites
thx for your help, i have a printing routine as follows:

GLvoid glPrint_IMG(GLint x, GLint y, char *string, int set) // Where The Printing Happens

glBindTexture(GL_TEXTURE_2D, texture_IMG[0]); // Select Our Font Texture
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base_IMG-32+(128*set)); // Sets The Base Character to 0
glCallLists(strlen(string), GL_BYTE, string); // Draws The Display List Text


so i try to use it like this: glPrint_IMG(0,0,&float_str,0);

But i get the following error:
error C2664: ''glPrint_IMG'' : cannot convert parameter 3 from ''class std::basic_string,class std::allocat
or > *'' to ''char *''
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

Share this post

Link to post
Share on other sites