Unicode string woes [SOLVED]

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
julescoder
Posts: 34
Joined: Thu Feb 18, 2010 5:24 pm

Unicode string woes [SOLVED]

Post by julescoder »

Hi, i am trying to converting a float value to display in a static text label.
Problem is how do i convert it to wchar_t , the type that static text label requires. Here a snippet so far:

Code: Select all

std::wstringstream s1;
std::wstringstream s2;

s1 << reciever.MouseState.Position.X;
s2 << reciever.MouseState.Position.Y;

text->setText( (s1.str() + s2.str()));

I get error :
error C2664: 'irr::gui::IGUIElement::setText' : cannot convert parameter 1 from 'std::basic_string<_Elem,_Traits,_Ax>' to 'const wchar_t *'
[/code]
Last edited by julescoder on Sat Feb 20, 2010 3:46 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to use .c_str()
julescoder
Posts: 34
Joined: Thu Feb 18, 2010 5:24 pm

Post by julescoder »

The wstringstream object does not have the .c_str() function. I am using visual c++. Is there any other way to do it ?
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Post by Memorial76 »

Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

looks horrible but should work :)

Code: Select all

text->setText( stringw( std::wstring( s1.str() + s2.str() ).c_str() ).c_str() );
Never take advice from someone who likes to give advice, so take my advice and don't take it.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to use c_str() on the created wstring object, not on the stringstreams. Just take your first code and add it inside the outer braces. It's also almost what Bate suggested, just one constructor less (which is already implicit by the operator+)
julescoder
Posts: 34
Joined: Thu Feb 18, 2010 5:24 pm

Post by julescoder »

It worked. Thanx for all your help. I' m from a c# background, so getting this conversion of different types of strings was confusing.

the code :

Code: Select all

text->setText(std::wstring( s1.str() + s2.str() ).c_str());
Post Reply