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 / Open text file with DarkGDK

Author
Message
Szymat
14
Years of Service
User Offline
Joined: 17th Oct 2010
Location:
Posted: 10th Aug 2011 16:32
Hi!

I have a little problem here, you see, I want to load text file (my options) from a text file, and freely save options to this file, now I have problem even with load.

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 10th Aug 2011 20:09
i don't even see where you are attempting to open the file, screw GDK built-in file system everyone reports failure and errors with them, either use std::fstream (C++ style) or old C methods:



google is your friend, everything's there.

Szymat
14
Years of Service
User Offline
Joined: 17th Oct 2010
Location:
Posted: 10th Aug 2011 23:27
Problem is i'm trying to include iostream and fstream, but it get angry with darkGDK, i tried include before and after darkgdk include.
Is there any possibility to start main.cpp first (include there without darkgdk) and then go to game.cpp with all variables from main?
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 10th Aug 2011 23:47
you will need to go to menu -> project -> <projectname> properties -> configuration properties -> C/C++ -> code generation and set runtime library to /MT

your GDK code will always start at void DarkGDK ( void ) { /*here*/ }, you can have tens and hundreds of cpp files, but your code will still start there, you can, from there, call functions that are in other files, though, you will need to tell the compiler that these function are defined somewhere, basically, create a .h file, and write the function prototypes there, and dont forget the header guards (#pragma once, for example) in the .h file.

you can also use the extern keyword to access, for example global variables in main.cpp from other files

Mistrel
Retired Moderator
19
Years of Service
User Offline
Joined: 9th Nov 2005
Location:
Posted: 11th Aug 2011 01:06
http://hughesbennett.co.uk/public/cpp/cppref/cppio/all.html

I found an excellent reference online for C++ I/O. You can use C methods, but ifstram/ofstream really is the way to go in C++.

Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 14th Aug 2011 00:58
I use the following:


The important thing to remember is that the file has a specific size. You can read each byte to find a value if you have a file written something like this:

ScreenW = 1024
ScreenH = 768
ScreenD = 32
PlayerHealth = 100
PlayerAmmo = 500

There are many ways to do this, but I like to write my files compact-- this makes them impossible to read with a text editor, but I know the size of each item I put into the file.

The fastest code is the code never written.

Login to post a reply

Server time is: 2024-11-19 08:40:39
Your offset time is: 2024-11-19 08:40:39