Appending many wchar_t

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
Guest

Appending many wchar_t

Post by Guest »

Hi,
I am not so experienced yet in cpp, coming from pascal/delphi.
I have some problems with the wchar_t

if I have some of them, for example:

Code: Select all

wchar_t* char1 = L"BlablaBla";
wchar_t* char2 = L"BlubBlubBlub";
wchar_t* char3 = L"BloBloBlo";
And then I want to add these three as a parameter to, for example, guienv->addStaticText(...);

In Pascal I wrote

Code: Select all

guienv->addStaticText(char1+char2+char3,[...]);
In cpp this doesn´t work.

I wonder how I do this in cpp. I would be glad if anybody could help me.
thx in advance!
[/code]
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

wchar_t* acts similarly to char*

as C/C++ is very basic, it does not support fluid string types, or dynamic arrays, hashed arrays, etc. However classes that offer this functionality are often supplied.

for typical char*, you can use std::string which provides operator overloading for functionality such as what you described (ie: str1 = str2+str3 )

std::string uses char* internally however, and you want to use wchar_t

for this purpose, Niko has coded his own string class which is a template. you can make an irr::core::string<wchar_t>, which will provide the functionality you are looking for.

for instances that require a wchar_t*, use the c_str() method to extract a pointer to your string
a screen cap is worth 0x100000 DWORDS
Guest

Post by Guest »

It works perfectly. Thx for your help. Only one question is remaining :)

I have now:

Code: Select all

[...]
string<wchar_t> string1 = "String1";
string<wchar_t> string2 = "String2";
string<wchar_t> string3 = "String3";
[...]
Later I have another string, I want to add the first three strings and insert some words manually, so it would look like:

Code: Select all

string<wchar_t> charNew = "These are all Strings: "+string1+string2+string3;
This wont work because "These are all Strings: " is no string, of course. But how can I make a "Just-In-Time" String without having a new Object. I would not look nice if I would write:

Code: Select all

string<wchar_t> temp = "These are all Strings: ";
string<wchar_t> charNew = temp+string1+string2+string3;
Thank you for your help!
mq
Posts: 8
Joined: Wed Nov 26, 2003 4:04 pm
Location: Heidelberg, Germany
Contact:

Post by mq »

btw: I am mq, thaught I was logged in :oops:
mq
Posts: 8
Joined: Wed Nov 26, 2003 4:04 pm
Location: Heidelberg, Germany
Contact:

Post by mq »

Does nobody know how to create "Just-In-Time"-Strings? I would search in google but what should I look for? "Just-In-Time object creation"?
I would be glad if anybody could just post one line of code :wink:

thx in advance,
mq
[Knowledge is king] ;-)
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

the reason it doesnt work is because you're not using a wchar_t static string--
"string<wchar_t> temp = "These are all Strings: "; " that wont event work, you need to put the "L" in front of your string to make it a static wchar_t

ex:
string<wchar_t> charNew = L"These are all Strings: "+string1+string2+string3;

The L there is a pre-compile macro which tells the compiler that the static string next to it is a wide character string. so:
"this string is a static 'char' string"
L"this string is a static 'wchar_t' string"
a screen cap is worth 0x100000 DWORDS
mq
Posts: 8
Joined: Wed Nov 26, 2003 4:04 pm
Location: Heidelberg, Germany
Contact:

Post by mq »

Thx for your answer, but I tested it with and without a "L" and both don´t work.

string<wchar_t> string1 = L"String1"; //with or without L, both dont work
string<wchar_t> string2 = L"String2"; //with or without L, both dont work
string<wchar_t> string3 = L"String3"; //with or without L, both dont work
string<wchar_t> charNew = L"These are all Strings: "+string1+string2+string3; //with or without L, both dont work

The error is:
main.cpp(73): error C2677: Binärer Operator '+' : Es konnte kein globaler Operator gefunden werden, der den Typ 'irr::core::string<T>' akzeptiert (oder keine geeignete Konvertierung möglich)
with
[
T=wchar_t
]

(binary '+' operator: There is no global operator that supports the type 'irr::core::string<T>' (or there is no conversion possible)

thx and regards,
mq
[Knowledge is king] ;-)
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

hrm. string<wchar_t*> maybe? though that doesnt seem right..

otherwise, you can just create one on the spot:
string<wchar_t> blah = string<wchar_t>("blah blah blah...");
blah = blah + string<wchar_t>(" and more blah\n");

i think that'd work
a screen cap is worth 0x100000 DWORDS
mq
Posts: 8
Joined: Wed Nov 26, 2003 4:04 pm
Location: Heidelberg, Germany
Contact:

Post by mq »

Yeah the 2nd possibility is working very well. I thank you very much :D
Best regards,
mq :)
[Knowledge is king] ;-)
Post Reply