|
-
May 5th, 2001, 09:44 PM
#1
Thread Starter
Lively Member
Opening and Reading a file, easy question
Hi All,
Just a quick question.
I have recently created this mini grid game using the a char [10] [10]. I want to make it so that it reads from a file at the start of my game and load the values into the [10][10] char.
the actual file, info.dat will have all 100 chars on one line as i thought it would be easier to retrieve, so the file would look something like..
B EDF EGD JHD etc
the program must read and include the spaces into the 10*10 Char as well, so basically it just reads on char from the file then writes it to the first array then the second one and so on right until it's added all of the letters/spaces to the 10*10 char.
I've worked out most of the stuff I just need some help to fill in the gaps....
#include <fstream.h>
int disp[10][10]
ifsteam thefile;
int main()
{
thefile.open("info.dat");
//add a for statement that keeps going until it's read all 100 chars
//add another for statement to keep going until the end of the row then move to the next one.
thefile.close();
Any help would be greatly appreciated!
Thanks.
Regards,
Smithy.
-
May 6th, 2001, 01:56 PM
#2
Hyperactive Member
Code:
#include <fstream.h>
#include <iostream>
int main()
{
int disp[10][10];
char ch;
int i;
ifstream in("info.dat", ios::in | ios::binary);
ofstream out("info.dat",ios::out | ios::binary);
for(i=0;i<100;i++){
in.get(ch);
out.put(disp[i][i]);
}
in.close();
out.close();
return 0;
}
Matt 
-
May 6th, 2001, 06:14 PM
#3
Monday Morning Lunatic
It should be fstream not fstream.h
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 7th, 2001, 01:39 AM
#4
Thread Starter
Lively Member
Thanks
Hi,
Its OK now, I've used a different method which works quite nicely.
thanks for your efforts though!
Regards,
Smithy.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|