Sorry man wasnt me. I assume your talking about Metal Gear Solid 2? But it wasnt me. Sorry.
Mess with the best,
Die like the rest!!
🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Newbie Question.........
quote: Original post by Android 13
What line/lines of code would you use to let the user save thier progress.
That''s a complex topic (not the saving - the progress bit). Essentially you need to save all important variables and statistics so that when the user loads it back, everything is exactly as they left it.
Anyway, saving a file:
- Create a file stream object. Output file streams are good enough.
- Open the file to save to; if you want to create the file if it doesn''t already exist, be sure not to set the ios::nocreate bit.
- Write the data out using the standard insertion operator (<<), just as you would with cout.
- Close the file.
Code to do it? Man, that''s half the fun (figuring stuff out)!
Okay, I relented:
#include <fstream>#include <iostream>using namespace std; //int main(int argc, char *argv[]){ ofstream ofile; // this will open the file if it exists and overwrite its contents: ofile.open("filename.ext"); // to append (add to the end) data to the file, use this: // ofile.open("filename.ext", ios::app); // // make sure the file opened correctly: if(ofile.fail()) { cout << "Could not open filename.ext!" << endl; return -1; } // you can now write data out just like cout (the beauty of stream objects) int i = 42; float f = 42.00f; char c = 42; ofile << i << endl // save the integer to the file; newline << f << endl // save the float to the file; newline << c << endl; // save the char to the file; newline // close the file: ofile.close(); return 0;}
But, how do we write a page of data? Is it very advanced?
What I''ve used and failed:
It seems that with these, I can only get a few lines of input.
I welcome any comments and advice.
What I''ve used and failed:
ofstream out;for(int x=0;x<strlen(str);x++){ out.get(*str[x]);}out.close();
It seems that with these, I can only get a few lines of input.
I welcome any comments and advice.
savagerx: why are you get()''ing from an output stream? (I''ll assume that was a typo). Also, you only get up to the length of your str (buffer) characters of data
To read in a "page" of data (what is a page? Let''s assume a page is 25 lines for this discussion - or 1024k in 80x25?)
To read in a "page" of data (what is a page? Let''s assume a page is 25 lines for this discussion - or 1024k in 80x25?)
ifstream in;in.open("filename.ext");if(in.fail()){ cout << "failed to open filename.ext" << endl; return -1;}char str[255]; // be excessivewhile(!in.eof()){ in.getline(str, 255, ''\n''); // break on newline if(in.fail()) break; // save data in str somewhere; my favorite place is in a vector // this time though, we''ll just print it to the screen: cout << str << endl;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement