wchar_t to string or char

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
emre2345
Posts: 37
Joined: Mon Jul 09, 2007 7:02 pm

wchar_t to string or char

Post by emre2345 »

hi everyone, i have a couple of questions. first;

i wanna convert string or char to whar_t, for ex. when the button is down i want to write a numerical variable to a static box, how can i do this?

my second question is:


Image
on some machines the quality of images can fall, what can be the reason of this thing?
Last edited by emre2345 on Tue Feb 05, 2008 7:40 pm, edited 2 times in total.
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Hi,

You can convert a string like this:

Code: Select all

core::stringw s = "test";

s.c_str();
I am not sure what you mean with "when a button is down". If you mean a gui element, use the CIrrEventReceiver class for it (you can find this in the code snippet forum).

And a tutorial on how to use it, can be found in the "FAQs, Tutorials, Howtos, and external tool lists" forum.

About your second question, it's the graphics card what makes the difference in the quality.

For example, a build-in graphics card gives you a really poor images. This goes for older graphics cards too.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

on some machines the quality of images can fall, what can be the reason of this thing?
some cards prefer only power of two textures, have you tried that?
emre2345
Posts: 37
Joined: Mon Jul 09, 2007 7:02 pm

Post by emre2345 »

xDan wrote:
on some machines the quality of images can fall, what can be the reason of this thing?
some cards prefer only power of two textures, have you tried that?
i dont understand what you mean
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

emre2345 wrote:
xDan wrote:
on some machines the quality of images can fall, what can be the reason of this thing?
some cards prefer only power of two textures, have you tried that?
i dont understand what you mean

Hi,

xDan is right, that could be a possibility too.

What he means is that the size of the texture has to have these values:

1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024.

For example, 128 x 256 or 512 x 128.
emre2345
Posts: 37
Joined: Mon Jul 09, 2007 7:02 pm

Post by emre2345 »

ok i see, thnx
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Re: wchar_t to string or char

Post by Seven »

emre2345 wrote: i wanna convert string or char to whar_t

Code: Select all

wchar_t wtemp[255];
wchar_t* ConvertToWChar(char* text)
{
	// Convert to a wchar_t*
    size_t origsize = strlen(text) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    mbstowcs_s(&convertedChars, wtemp, origsize, text, _TRUNCATE);
	return wtemp;
}

not the prettiest, not the fastest. it works though :)
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Another one.

Post by wITTus »

Hi.
I got the same problem somehow.
But it was rather the contrary.
For the sake of completeness:

Code: Select all

#include <string>
#include <cstdlib>
#include <cwchar>

void toString(std::string& dst, const wchar_t* src)
{
	size_t newlen = std::wcslen(src) + 1;
	char* tmp = new char[newlen];
	std::wcstombs(tmp, src, newlen);
	dst = tmp;
	delete[] tmp;
}
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Re: Another one.

Post by Rytz »

wITTus wrote:Hi.
I got the same problem somehow.
But it was rather the contrary.
For the sake of completeness:

Code: Select all

#include <string>
#include <cstdlib>
#include <cwchar>

void toString(std::string& dst, const wchar_t* src)
{
	size_t newlen = std::wcslen(src) + 1;
	char* tmp = new char[newlen];
	std::wcstombs(tmp, src, newlen);
	dst = tmp;
	delete[] tmp;
}
I didn't read the whole thing so I'm not sure what the original problem was but you might want to try this instead:

Code: Select all

dst.assign(tmp);
Image
Post Reply