Convert stringc to normal char array

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
Dragfang
Posts: 21
Joined: Tue Mar 02, 2010 4:08 pm

Convert stringc to normal char array

Post by Dragfang »

I want to convert a stringc to a normal char, since I'm using <fstream> to handle configuration text-files. I'm making a game and I want the user to be able to choose which maps he wants to play. This is done using a box called MAP_BOX.

Code: Select all

    core::stringc mappath;
    mappath += "maps/";
    mappath += root->getElementFromId(MAP_BOX, true)->getText();
    mappath += ".obj"

	scene::IAnimatedMesh* mapmesh = smgr->getMesh(mappath);

    char filespath[50];
    filespath = mappath???
    writefile.open(filespath);
This works great, but I now want to use <fstream> to make a .txt file for configuration data. Thing is, I can't use the stringc-string to create the .txt-file, therefor I need to convert the stringc to a char[];
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

Use the c_str() method.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Dragfang
Posts: 21
Joined: Tue Mar 02, 2010 4:08 pm

Post by Dragfang »

Thx for the fast reply

Code: Select all

char filespath[50];
filespath = mappath.c_str();
Like that? Im getting an error in Dev-C++ saying "incompatible types in assignment of `const irr::c8*' to `char[50]' " using the code above.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

No, forget the array, just use mappath.c_str() to open the file.

Code: Select all

writefile.open(mappath.c_str());
And i would recomend you to switch to code::blocks also ;)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Dragfang
Posts: 21
Joined: Tue Mar 02, 2010 4:08 pm

Post by Dragfang »

Ah, works perfectly. Thank you!

I'll take a look into code::blocks, thx for the tip! :)
Post Reply