ARGH! why so many different 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
dgrafix
Posts: 116
Joined: Sun Nov 18, 2007 2:36 pm

ARGH! why so many different strings!!

Post by dgrafix »

std::string
stringw
c8*
char*
wchar_t

????? ??

I thought i was getting somewhere with strings in c++. Ive got functions to convert my strings to wchar_ts and stringws to char*s

I was wrong :(

Now im hit with a new one core::stringC that doesnt seem to work with anything. I need to stringC=gettextexturename() which returns this and then use removetexture (c8*) the result.

Probably something quite simple but have not got a clue
Why on earth are there so many types of string :?
C++/Irrlicht Noob pl3se B p4t1ent.
Visit www.d-grafix.com :)
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

well...

in c++(ansi) you have just wchar_t, char and std::string...

char* its an array of chars, not the same as std::string why is that...? cause std::string its an object, and char is just a data type... thus... string has methods and members... its not just a bunch of characters....

wchar_t* its a wide char type character array...so its also not the same as char* cause the chars stored are longer... a char variable stores values only from 0 to -128 to 127 and wchar_t stores bigger values...


Now irrlicht has its own typedefs for these types...

irr::c8* = char*
irr::core::string< T, TAlloc > = (sorth of) string
stringw its a string made of wchar_t characters
theres also
stringc wich is a string made of c8 characters

again... irr::core::string< T, TAlloc > its a object with methods and members... c8 and wchar_t arent

... i hope this has cleared a little why so many string types.... im sure that any of the engine's developers can explain better that i did

Best regards
dgrafix
Posts: 116
Joined: Sun Nov 18, 2007 2:36 pm

Post by dgrafix »

Thanks for the explaination, its sort of as i thought, but thats kind of filled in the blanks :)

If stringc is a type of c8* chars, why can i not do:

stringC astring="hello";
c8 * chars = astring
C++/Irrlicht Noob pl3se B p4t1ent.
Visit www.d-grafix.com :)
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

cause it should be:

Code: Select all

core::stringc astring = core::string("hello");//this line can also be = to the one u wrotre
c8* chars = astring.c_str();
thats because as i said a stringc is a object and a c8* is an array...therefor in order to get the c8 array from a stringc object u need to call the correct method, in this case c_str()
robertgarand
Posts: 69
Joined: Fri Feb 22, 2008 6:47 pm
Location: montreal
Contact:

I agree-> there's too many in use

Post by robertgarand »

You're right Dgrafix,

Why isn't there only the AnsiString, that holds it all, large and small arrays.
No more need for type conversion or else., just say it is the standard.

We can do anything/everything with chars using AnsiStrings.

Je m'en sers autant que je peux :!:

Robert
If it can't be writen, it can't exist
dgrafix
Posts: 116
Joined: Sun Nov 18, 2007 2:36 pm

Post by dgrafix »

Lol. dunno, i guess it makes it a crapload faster and more powerful. Still, a simple generic string type that converts easily would be useful. Although now i understand the fact that the "string" is in fact just a class for char arrays it makes it kind of the same... in a way.

I guess its hard to get into remembering that in C there is no "string" :)

astring.c_str(); <<---Great! thanks a lot that has just made it all clear! Thx Radiant


Still dont get the point behind wide characters though :/
C++/Irrlicht Noob pl3se B p4t1ent.
Visit www.d-grafix.com :)
radiant
Posts: 112
Joined: Fri Feb 22, 2008 8:04 pm
Location: Mexico

Post by radiant »

wide characters are(this is a personal apreciation) intended for when u need to stuff in non-standard ascii or unicode,because chars only stores 255 diferent values... and belibe me there are not 255 values for diferent characters...
unicode has thousands of diferent symbols..... so those wouldnt fit into a char...

Best regards
switch_case
Posts: 34
Joined: Sat Mar 08, 2008 12:46 pm
Location: Germany, FFM
Contact:

Post by switch_case »

for example the chinese alphabet code is stored in wchars i think, because they got way more than 255 characters to deal with.

and i think you learned c++ with borland, right? ^^
i did the same mistake, ansistring is fine, but forces you to be lazy and at the time you have to deal with "real", non-borland c++, you will definetly bite the dust at first....

and if anything in irrlicht doesn't work,because you gave it the wronge type of string, try to use a diffrent one, f.e. stringw, stringc, and w_chart, and in the function just try to use string.c_str()... playing around with that will make it work sometimes, and after a time you know, wich functions want to have wich strings ;) (i had problems with that at first, too ;) )
if life could only be written in C++...
so much features, money++, remove_childs(), choose parents, life = new life, and no more <IDIOT> templates !
if you're looking for an nerdy coding language: http://lolcode.com/
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

c8* is a pointer to a 8 bit array.
wchar_t* is a pointer to a 16 bit array.

stringc is a string object of c8 type.
stringw is a string object of wchar_t type.

c_str() returns the c8*/wchar_t* of the object as const.

e.g.

Code: Select all

stringw IAmAString = L"Hello World!";
wchar_t* PrimitiveString = IAmAString.c_str();
Because IAmAString is a stringw c_str() would return a wchar_t*. If it was a stringc it would return c8* == char*.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

wchar_t is not necessarily 16bit wide, e.g. on Linux it's 32bit wide. That's why wchar_t is not really nice to work with. But it does help to work with some enhanced fonts.
Post Reply