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 / Saving a string into a file.

Author
Message
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 15th Dec 2011 19:35
I'm making a game that needs to save a string into a file every so often. I've tried the DarkGDK function (dbOpenToWrite, dbOpenToRead,...) but those don't work very well. So i've tried to use fstream. I used it before in a different project but that one wasn't made with DarkGDK, just a console program. I used this code:


I get an error: "error C2065: 'ifstream' : undeclared identifier"
Does fstream not work with DarkGDK?

vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 15th Dec 2011 20:02
I had something like that in my previous game.. but sorry i lost my source :S

I Used fstream and then file >> "string"; it worked nice...

But sorry dont help you..

C++ Medium 3.5/5
VB6 Advanced: 4/5
VB.NET Advanced: 4/5
Hassan
14
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 15th Dec 2011 20:05 Edited at: 15th Dec 2011 20:06
you should use "using namespace std" or using std::ifstream", or use std::ifstream indirectly (also, you could double-check the header name, im not sure)

MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 15th Dec 2011 20:55
vitinho444 perhaps my wiki can help as a repository?

I would have thought VB had such functions natively...
Looks like I will be creeping ever closer to PureGDK 2.0. at this rate...

TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 16th Dec 2011 09:37 Edited at: 16th Dec 2011 09:37
Wizz, for one thing you are including fstream and then declaring ifstream variables. That won't work.

Perhaps more importantly, ifstream is only for READING data, not outputting it.

Use fstream instead. Here's an example that reads and writes files using fstream.:


Amazing Simulation
www.amazing-forum.com
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 16th Dec 2011 12:31
I included using namespace std;
no errors now, but it doesn't write the word to the file. The file is empty.
TerryRussel: You told me I shouldn't include fstream and then declare ifstream variables, but in your code, you include fstream and then declare ifstream variables.
Anyway... I'm really don't get fstream. Everywhere I look people use different code and I can't really tell what it does. The code I posted worked for my win32 console program but it doesn't work here. Does anyone know any good tutorials for complete noobs on fstream?

JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 16th Dec 2011 14:24
std::ifstream is for Read-only. It has none of the output functionality built in to reduce the overhead when all you want to do is read a file's contents.

std::ofstream is for Write-only. It has none of the input functionality for cases where you simply want to write to the file (ie: error.log)

std::fstream is for Read-write and has both input and output functionality.

Change you're ifstream to fstream like so:

In you're case above, you are asking the file for a value to be placed into the word variable (and you said yourself that the file is empty).

To write the word variable to the file change the >> (input) into << (output) which won't work because ifstream is input only. The << (output) only works for ofstream and fstream.

I hope this helps clarify things flu you.

JTK
TerryRussell
13
Years of Service
User Offline
Joined: 11th Dec 2010
Location: Chichester, UK
Posted: 16th Dec 2011 20:03
Yes, looking at my message, I didn't put it clearly enough. I did say "ifstream is only for READING data, not outputting it." but I didn't make it as clear as JTK has done.

My excuse is that it's nearly Christmas and I am very old.

Amazing Simulation
www.amazing-forum.com
Wizz
14
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 18th Dec 2011 00:54
I. Am. Retarded. I was using ifstream to save a string insted of ofstream. I just copied it from an old program of mine without thinking. I didn't get what you guys were trying to tell me. Thank you all!

Login to post a reply

Server time is: 2024-03-29 06:55:34
Your offset time is: 2024-03-29 06:55:34