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
Converting std::string to irr::c8*
-
Memorial76
- Posts: 103
- Joined: Mon Aug 10, 2009 8:22 pm
- Location: France
-
Memorial76
- Posts: 103
- Joined: Mon Aug 10, 2009 8:22 pm
- Location: France
Nope, it doesn't work:Lambda wrote:Code: Select all
std::string str = "Hello, world"; irr::c8* str2 = str.c_str();
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!!!
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
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
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.
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
-
Memorial76
- Posts: 103
- Joined: Mon Aug 10, 2009 8:22 pm
- Location: France
This would work too:
Code: Select all
std::string test = "bla";
c8* test2 = const_cast <c8*> (test.c_str());