Converting std::string to irr::c8*

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
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Converting std::string to irr::c8*

Post by Memorial76 »

I tried to search all over the web but couldn't any satisfying solution. Here is my problem:

I have a .txt in which i write some information about my objects. Of course, I use std::strings and streams to deal with that and it works.

But I can't give Irrlicht std::strings as parameters (as filenames for example) and i can't find any convertion method to transform my std::strings to irr::c8* as required.

Does any of you has a solution?
Is there another way to read txt files through Irrlicht?

Thanks for all
Lambda
Posts: 126
Joined: Wed Feb 27, 2008 3:00 pm
Location: Spain, Huelva
Contact:

Post by Lambda »

Code: Select all

	std::string str = "Hello, world";
	irr::c8* str2 = str.c_str();
Image
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Post by Memorial76 »

Lambda wrote:

Code: Select all

	std::string str = "Hello, world";
	irr::c8* str2 = str.c_str();
Nope, it doesn't work:

1>c:\documents and settings\mes documents\programmation\toolbox.cpp(109) : error C2440: 'initialisation' : impossible de convertir de 'const char *' en 'irr::c8 *'
1> La conversion perd les qualificateurs

As i said i searched solutions over the net, it would have been too easy!!!
jpoag
Posts: 25
Joined: Mon Aug 10, 2009 1:00 am

Post by jpoag »

The error says you're missing the 'const' modifier. Either add 'const' to the str2 declaration or use C-Style typecasting on the c_str() return.
-James
r2d2
Posts: 211
Joined: Mon Nov 24, 2003 5:22 pm

Post by r2d2 »

You could use irrlicht's stringc class.

Code: Select all

std::string test = "testing";
core::stringc test2 = test.c_str();
R2D2's Irrlicht Mods
Messed up with my database so the page is not working at the moment -.-
CPU: Core 2 Quad Q6700RAM: 4096 mb Graphics: Radeon 4850 512mb Sound: on board InternetConnection: DSL
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Post by Memorial76 »

jpoag wrote:The error says you're missing the 'const' modifier. Either add 'const' to the str2 declaration or use C-Style typecasting on the c_str() return.
:oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops: :oops:

Yes, that is true, but when I modify all my parameters to 'const' my program does no longer work properly. It seems that the chain is modified because the program crashes with a problem like "pointer to 0". This may be due to my functions, i'm gonna have a closer look at it. Thanks a lot!
Last edited by Memorial76 on Tue Aug 11, 2009 5:58 pm, edited 1 time in total.
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Post by Memorial76 »

this is the error :oops:

Exception non gérée à 0x0041271e dans Asgard.exe : 0xC0000005: Violation d'accès lors de la lecture de l'emplacement 0x00000000.
Memorial76
Posts: 103
Joined: Mon Aug 10, 2009 8:22 pm
Location: France

Post by Memorial76 »

Thanks a lot to all,
finally it works perfectly well with c_str and some correction to my program :P
-insane-
Posts: 18
Joined: Tue Aug 04, 2009 4:41 pm
Location: Germany

Post by -insane- »

This would work too:

Code: Select all

	std::string test = "bla";
	c8* test2 = const_cast <c8*> (test.c_str());
Post Reply