Hello, I'm a semi-experienced programmer... just not to C++. I've used QBasic (please don't laugh at me)... and I'm ready to use a real language. Using files isn't hard... but what I want to do and what I know how to do are two different things. So...
exitprog is a global boolean used by a function I haven't made yet and main. This is a RPG, and I've worked out the [psuedo]random numbers and taking keys (that's why windows.h is in there, though I hate importability). My problem is that I don't know how to take a variable out of a file. I hate to do it, but I'll put a string header in and make the file text format... but that would really be a pity, it's a game, and that would make it MAJOR hackable.Code:#include <iostream> //cout stream, so you can see #include <stdlib.h> //rand() function #include <ctime> //time() function -for srand() #include <fstream.h> //files #include "windows.h" //accepting keys without pressing enter (much nicer) bool exitprog = false; int main(int argc, char *argv[]) { cls(); cout << "John's battle game... very beta\nFilename:"; int str, def, spd, hp, gold; char buffer[32], bufferb[32], bufferc[32]; cin >> buffer; ifstream filein(buffer, ios::binary); if (filein.eof) { filein.close(); ifstream fileout(buffer, ios::binary); cout << "\nThis file is not yet initialized. Character name?\n"; cin>>bufferb; for (int x=0; x<31; x++) { //I'm so terribly sorry... fileout << bufferb[x]; //my braces are a nightmare to read. } fileout << 7 << 7 << 7 << 25 << 10; fileout.close(); filein.open(buffer, ios::binary); } for (int y=0; y<31; y++) { filein >> bufferc[x]; } filein >> str >> def >> spd >>hp >> gold; //It's time: The do...while. This goes until it's time to end. do { exitprog = true; //lazy functstubbing developers!!! }while(!exitprog) //file save code... //Debug information. If any needed. system("pause"); // <- remove this (developer only) return 0; //ah, the end. My program is done. }
It's not finished but I think it's stubbed up pretty well and should run... all my errors are contained in the code posted. I am using functions posted as tutorials, but I'm not marketing, this will only go around my house.
and vets- don't let me go around thinking I know what's going on... I figure I got this under control and if I don't, straighten me out before I embarass myself. Thanks.



LinkBack URL
About LinkBacks


