Page 1 of 1

String conversion and AnimationEndCallBack

Posted: Thu Dec 29, 2005 4:13 pm
by AshmenGlue
I've got 2 questions.


1. How do I convert a char array into a const wchar_t so I can display it in Irrlicht? I have a

char name[256];


2. How EXACTLY do I use the setAnimationEndCallBack function in IAnimatedMeshSceneNode. I've already declared an IAnimationEndCallBack. I'm not sure what to do with the OnAnimationEnd fuction and all that.

Thanks for helping.

Posted: Thu Dec 29, 2005 4:20 pm
by sudi
1.
char name[256];
char* nam;
nam = name;
wchar_t string = wstring(nam).c_str();

maybe it also works when u do:
char name[256];
wchar_t string = wstring(name).c_str();

but i dont know....first one should just work perfectly

Posted: Thu Dec 29, 2005 5:41 pm
by AshmenGlue
Here's what I did:

Code: Select all


char name[256];
char* playernametemp;
const wchar_t* playername;

playernametemp = name;
playername = std::wstring(playernametemp).c_str();

When I compile I have an error that says "left of c_str() must have class/struct/union type" and right below it is a "type cast: cannot convert from char* to std::basic_string"

Posted: Thu Dec 29, 2005 6:55 pm
by sudi
ups...i think u don't need the .c_str()
its only needed when u have something else in there like an int....
my fault

Re: String conversion and AnimationEndCallBack

Posted: Thu Dec 29, 2005 7:31 pm
by dhenton9000
AshmenGlue wrote:I've got 2 questions.


2. How EXACTLY do I use the setAnimationEndCallBack function in IAnimatedMeshSceneNode. I've already declared an IAnimationEndCallBack. I'm not sure what to do with the OnAnimationEnd fuction and all that.

Thanks for helping.

I've got an animationcallback sample at http://www.s-fonline.com/webhosting/dhenton9000 Look for the menu option for the NewtonIrrlicht integration FPS demo. Then grep the source for OnAnimationEnd. The milkshape animation signals to Newton to put up the door barrier when the door is in closed mode.

hth

Posted: Thu Dec 29, 2005 8:48 pm
by AshmenGlue
Sudi: Even after removing the c_str() I still get the second type cast error. Why is that so?

dhenton9000: I'm downloading it right now. Thanks.

Posted: Fri Dec 30, 2005 9:43 am
by rincewind
Don't use the STL wstring but the irrlicht built-in stringw:

Code: Select all

char name[256];
// fill name array with data
// ...
const wchar_t *string = irr::core::stringw(name).c_str();

Posted: Fri Dec 30, 2005 10:51 am
by AshmenGlue
This is really really very frustrating. rincewind your code compiles fine but when I try to print it I get some crazy symbols or hexidecimal.

I've tried printing the result with printf (I get crazy stuff), with cout (hexidecimal), with wcout(nothing shows up). I even tried converting the wchar_t back to a string with:

std::string converback;
convertback = stringc(playername).c_str(); //playername is a converted wchar

and all it shows me is more crazy symbols when I try to print it. What is wrong here? Is it my conversion? My printing?

Posted: Fri Dec 30, 2005 11:11 am
by hybrid
I think you should start over and check the basics of pointers and classes in C++. You're completely messing around with pointer to (w_)chars and (w)string classes. If you do a c_str() you'll get a pointer to char, while stringc(X) will give you an object of whatever. std::string is also a class, but use a char assignement instead of copy constructor with explicit constructor on RHS.
And please check these thousands of threads on string conversion from the beginner's forum. You're not the only one who wants to display strings in Irrlicht.

Posted: Fri Dec 30, 2005 11:40 am
by sudi
@rincewise thats what i meant i mixed it up.....ups

@AshmenGlue u can't print w_chars on the screen without the irrlicht functions!

Posted: Fri Dec 30, 2005 12:42 pm
by Electron

Code: Select all

char name[256];
// fill name array with data
// ...
const wchar_t *string = irr::core::stringw(name).c_str(); 
The problem with this code is that you are storing a pointer to memory allocated for a temporary object. Try this instead

Code: Select all

stringw tmpName=name;
const wchar_t* wname=tmpName.c_str();

Posted: Sat Jan 07, 2006 6:59 am
by AshmenGlue
Sorry for not replying here. I've found the answer to the string problem. I used the STL func mbstowcs to convert a char* to a wchar_t*. It was that simple. I just store the received string in a char*, passed it into the funct and got my w_char_t* which I can then display on screen.

Sudi: Sorry I didn't elaborate but I wasn't using all of them to print on screen. Some were used to print into a Logger.txt and some were ouput-ed into the console window.