strings!!

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
interceptor
Posts: 22
Joined: Thu Aug 23, 2007 12:39 pm

strings!!

Post by interceptor »

This is bloody annoying. My biggest annoyance with this engine is the strings!

Current dilema: How can i convert a stringc or stringw to a c8?
loki1985
Posts: 214
Joined: Thu Mar 31, 2005 2:36 pm

Post by loki1985 »

both stringc and stringw have a c_str() method, just like regular c++ strings... read the documentation next time.
interceptor
Posts: 22
Joined: Thu Aug 23, 2007 12:39 pm

Post by interceptor »

loki1985 wrote:both stringc and stringw have a c_str() method, just like regular c++ strings... read the documentation next time.
Yea, thanks for that, but .c_str() gives me the problem of
cannot convert parameter 1 from 'const wchar_t *' to 'irr::c8 *'
I did actually read the manual first but i didn't understand, that's why i posted it on the forum. Isn't that what forums are for?
zillion42
Posts: 324
Joined: Wed Aug 29, 2007 12:32 am
Location: Hamburg, Germany

Post by zillion42 »

its not really what you're asking, but maybe it works...

Code: Select all

core::stringw test = "test";
core::string<wchar_t> test2 = test.c_str();
core::string<char> test3 = test.c_str();
Last edited by zillion42 on Fri Feb 06, 2009 8:30 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 »

No, the forums are an answers knowledge base first, which you should query. So do the search first. Should bring up hundreds of threads which already solved this. There are basically two ways, one is correct for all encodings, one only works with the usual ANSI characters or little more.
dgrafix
Posts: 116
Joined: Sun Nov 18, 2007 2:36 pm

Post by dgrafix »

I had the same problems, comming from a b3d, bmax, c#, php background i completely agree c/c++ string handllings a mess,
so do what i did, Create your own wrappers for strings. You can quite easily implement high level methods like Replace, Mid, Trim etc.
then you can use ".c_str" for quickly convertig it to an array.
basically keep everything as a "string" in your prog, and write your own conversion functions just once for using with irrlicht etc...
Last edited by dgrafix on Mon Feb 09, 2009 1:43 pm, edited 4 times in total.
C++/Irrlicht Noob pl3se B p4t1ent.
Visit www.d-grafix.com :)
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

interceptor wrote: Yea, thanks for that, but .c_str() gives me the problem of
cannot convert parameter 1 from 'const wchar_t *' to 'irr::c8 *'
OK, if you call c_str() on a stringw, you'll get a wchar_t array out of it.

If you want a c8 array, then you'll have to convert the content of the wide string. If you're OK with the contents as ASCII/Latin-1 (rather than utf-8), then Irrlicht can do this for you, just by creating a narrow string from the wide string.

Code: Select all

	stringw wide(L"content");
	
	stringc narrow(wide);
	const c8* narrowContent = narrow.c_str();
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
interceptor
Posts: 22
Joined: Thu Aug 23, 2007 12:39 pm

Post by interceptor »

Well, i kinda gave up on using c8's. stringw suited my needs better.. :)
Post Reply