String conversion and AnimationEndCallBack
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
String conversion and AnimationEndCallBack
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.
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.
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
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
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
Here's what I did:
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"
Code: Select all
char name[256];
char* playernametemp;
const wchar_t* playername;
playernametemp = name;
playername = std::wstring(playernametemp).c_str();
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
its only needed when u have something else in there like an int....
my fault
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
-
- Posts: 395
- Joined: Fri Apr 08, 2005 8:46 pm
Re: String conversion and AnimationEndCallBack
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
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
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();
It has long been an axiom of mine that the little things are
infinitely the most important.
-- Sir Arthur Conan Doyle, "A Case of Identity"
infinitely the most important.
-- Sir Arthur Conan Doyle, "A Case of Identity"
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
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?
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?
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.
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.
@rincewise thats what i meant i mixed it up.....ups
@AshmenGlue u can't print w_chars on the screen without the irrlicht functions!
@AshmenGlue u can't print w_chars on the screen without the irrlicht functions!
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
Code: Select all
char name[256];
// fill name array with data
// ...
const wchar_t *string = irr::core::stringw(name).c_str();
Code: Select all
stringw tmpName=name;
const wchar_t* wname=tmpName.c_str();
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.
Crucible of Stars
Crucible of Stars
-
- Posts: 29
- Joined: Wed Oct 12, 2005 9:09 am
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.
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.