outfilename << variable << "or direct text. ";
But do to an interesting event today in 3rd block, we can't just double every cout line with a outfile line. Any suggestions or hints?




Posted 11 October 2001 - 10:20 PM
outfilename << variable << "or direct text. ";
Posted 12 October 2001 - 01:47 PM
first, your declare like this
ofstream outfile;
outfile can be replaced with any other thing you want, thats just what i always use.
next you have to open it
outfile.open("outfile.txt", ios::out);
the outfile.open part, needs to be the identifier you made to ofstrem, fo if you put ofstream out; then its out.open instead.
and before the .txt you can put any file name you want, and you can make it a .dat or a .txt if you want, or whatever you want, the program will read it.
next, is writing to the actual outfile
outfile << "w00t ";
use it like a normal cout, just replace cout, with whatever identifier you used, in this case, outfile.
there, you go, thats how its done. :)
(Edited by supersloth at 3:50 pm on Oct. 12, 2001)
Posted 12 October 2001 - 03:01 PM
ofstream out;
out.open("filename",ios::binary);
out.write("data",BIT_LOCATION);
out.close();
read from the file by using the ifstream object.
ifstream in;
in.open("name",ios::binary);
in.read(char [] data,BIT_LOCATION,BIT_READ_SIZE);
in.close();
this way is a little more stable and you don't have to write the whole file every time you write any data.
P.S. remember to chack the length so you don't overflow any buffers and crash your program, or corrupt the save file.
Cheers Sam
Posted 12 October 2001 - 04:09 PM
cout << "Enter yes or no. "; recordout << "Enter yes or no. "; cin.get(ans, 4); recordout << ans[4] << ' ';
Posted 12 October 2001 - 04:15 PM
Posted 12 October 2001 - 06:55 PM
Quote
Well that would work except classes are too advanced for them right now.
Posted 13 October 2001 - 01:16 PM
but, in your case, since this is the game craps, i dont think that would work out well, cause you dont know how many times they are playing, and used the same variables for every loop.
also, are you sure hanosh wants everything put into an outfile? last year, i usually only put the most important things into an outfile.
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
