Page 1 of 1

Convert std::string to wchar_t*

Posted: Mon Apr 30, 2007 8:50 am
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.

Posted: Mon Apr 30, 2007 10:56 am
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()