View Full Version : writing, please its urgent

01-23-2012, 04:05 PM
I need to read the integers from a file and print it.
I know how to read but not how to comvert int to char*.

my printing function goes like:

void glutPrint(float x, float y, LPVOID font, char *text, float red, float green, float blue) // text printing function
if(!text || !strlen(text)) return;
bool blending = false;
if(glIsEnabled(GL_BLEND)) blending = true;
while (*text) {
glutBitmapCharacter(font, *text);
if(!blending) glDisable(GL_BLEND);

coding in c++ using glut

01-24-2012, 01:54 AM
There's the standard C function sprintf(), or in C++11 there's std::to_string().

Alfonse Reinheart
01-24-2012, 07:23 AM
Warning: incoming rant.[/B]

Stop suggesting people use `sprintf`! At least 50% of all buffer overflow attack vectors come from using that function. It should never be used by anyone for anything.

If you don't like `std::stringstream` (and I can understand why), then use `snprintf`. If you're using Visual Studio, then you have to use `_snprintf`. Either way, there's no excuse for using a function as broken as `sprintf`.

End of rant[/B]

In any case, this page by Herb Sutter (http://www.gotw.ca/publications/mill19.htm) covers pretty much every way (pre-C++11) to turn a number into a string. Oh, and you may notice that turning a number into a string has nothing to do with OpenGL.

01-25-2012, 08:05 AM
Yes I understand that lol.

I got it to work this way:

stringstream conv1,conv2,conv3,conv4;
conv1 << stats.played;

glutPrint(1.5, 3,GLUT_BITMAP_TIMES_ROMAN_24, const_cast<char*>(conv1.str().c_str()), 1.0, 1.0, 1.0);

sorry about asking this question here.

Converting intiger to string