Hello;
I need to take a float value, which will always be a whole integer number, so can be cast with int(float) to become an int. I then need to het this int into a char* for a GL command. Can someone help?
Printable View
Hello;
I need to take a float value, which will always be a whole integer number, so can be cast with int(float) to become an int. I then need to het this int into a char* for a GL command. Can someone help?
you can use sprintf()
I think this will work tooCode:float n = 123;
char buf[8];
sprintf(buf,"%d", (int)n);
Code:float n = 123;
char buf[8];
sprintf(buf,"%.0f", n);
Can I do this without having to declare an array size for the char*
Code:#include <sstream>
std::stringstream Stream;
Stream << static_cast<int>(var);
const char* charPointer = Stream.str().c_str();
> Can I do this without having to declare an array size for the char*
Arrays are not pointers.
The array becomes a char* (learn about how arrays decay into pointers to the first element of the array) when you pass the array as a function parameter.Code:float n = 123;
char buf[8];
sprintf(buf,"%d", (int)n);
glSomeFunc( buf );