Convert std::string to wchar_t*

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
Kaki
Posts: 41
Joined: Thu Oct 12, 2006 12:19 pm
Location: France

Convert std::string to wchar_t*

Post by Kaki »

Hello

I want to create an EditBox whit a random name, like "Player234".

So , I do that :

Code: Select all

int DonneRandom ( int max ){
	int r;
	r = rand() % max +1; 
	return r;
}

wchar_t* DonneNomAleatoire(){
	int r = DonneRandom(1000);
	std::string nom = to_string(r);
	wchar_t* wch = nom; 
                return wch; 
}

wchar_t* text = DonneNomAleatoire();
And I have an error in DonneNomAleatoire : cannot convert std::string to wchar_t*.

Using the std::string is maybe a wrong way to define a random name.

How can I solve this problem ? Thanks for replies.
Luben
Posts: 568
Joined: Sun Oct 09, 2005 10:12 am
Location: #irrlicht @freenode

Post by Luben »

You can do this to store a number as a wide string

Code: Select all

stringw AString;
AString=(int)42;
If you need a pointer, do

Code: Select all

AString.c_str()
If you don't have anything nice to say, don't say anything at all.
Post Reply