Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Getting Variable from a file

Author
Message
RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 4th Sep 2008 14:07 Edited at: 4th Sep 2008 14:09
Hi

I am trying to understand file input and output, I can seem to get the DGDK functions to work properly. I did a forum search and could not find anything my speed.

I have a program, that is a level editor for my game, it has an array of tile data Tiles[625]

I need to output this data to a file (e.g. Map.txt). and then in my
game I also have an array Tiles[625], I want to match the Array in my game with the array in my level editor.

I am using the standard libs , so I can figure out how to write the data (maybe each tile's value on a diffrent line) and then I can read it with something like:

ifstream myfile ("Map.txt");
getline (myfile,line);

how would I convert it to an int value?
e.g. Tiles[20]= getline (myfile,line); ?

I just need some clarity on how to go about this, and how would I do this with DGDK functions, and is it better to use the fstream lib or the DGDK functions?

Thanks
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Sep 2008 17:02
I'll guess that 'line' is a char array or a pointer to char, and not a string object.



RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 4th Sep 2008 18:24 Edited at: 4th Sep 2008 18:27
no, I dont think it is a char

it says:
cannot convert parameter 1 from 'std::string' to 'const char *'

how would I read a line with DGDK?

dbReadWord()?

can I do something like sprintf(mychar, "%s", line); to convert it?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Sep 2008 18:46
If you are using the getline function for a specific reason, then change this line: Tiles[20]= atoi(line);
To this: Tiles[20]= atoi(line.c_str());

Otherwise, you can read the values directly from the file stream:


RancidRat
16
Years of Service
User Offline
Joined: 19th Feb 2008
Location:
Posted: 4th Sep 2008 18:48
Thanks alot!!! I did not know about the .c_str() thing. I just saw another example using it. Thanks for your help

Login to post a reply

Server time is: 2024-09-30 05:20:14
Your offset time is: 2024-09-30 05:20:14