Simple C++

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Simple C++

Post by Chev »

I'm new to C++ and am having difficutly converting a double to a const unsigned char*:

Code: Select all

Magnitude=Vector.getLength();
txtbox->setText(Magnitude);   // ERROR!! Need to convert!
text is for use in a IGUIStaticText* txtbox.
I've seen a bunch of string conversion tutorials for strings and such but I can't seem to find the translation of double to const unsigned char*.
Tequilla
Posts: 40
Joined: Mon Nov 10, 2003 3:42 pm
Location: Germany
Contact:

Post by Tequilla »

Hi,

in C/C++ you can't convert from number to text without any functions between. But the function you need is very easy:

(you have to include stdio.h and wchar.h)
wchar_t string[32];
swprintf(string,32,"%f",Vector.getLength());
txtbox->setText(string);

BTW:
If you want to print a integer to a text you have to write %d instead of %f. If you want to know more about that function, just search for printf(), or sprintf() on google (the parameters of sprintf and swprintf are the same). It's a very usefull function, which can not only convert number to strings...
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

Thank you tequila! :oops:
Chev
Posts: 37
Joined: Wed Nov 19, 2003 6:15 am

Post by Chev »

Looks like I'm getting closer but it still doesn't convert completely. It is getting converted to a character array successfully, but not all the way to 'const unsigned short *'

compiler error:

Main.cpp(64) : error C2664: '_snwprintf' : cannot convert parameter 3 from 'char [3]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast.

:shock:
Post Reply