![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
#1 |
Emerald Dragon
![]() Join Date: March 12, 2001
Location: spokane wa usa
Age: 41
Posts: 926
|
ok so i spaced over break [img]tongue.gif[/img] i can't seem to figure out/rember how to read a file into a struct. I have written the struck and opened the files and checked them. Can anyone point me in the right direction? All i need to do is put the info in the file into different parts of the struct. Goes off muttering about homework.
__________________
![]() |
![]() |
![]() |
#2 |
Emerald Dragon
![]() Join Date: March 12, 2001
Location: spokane wa usa
Age: 41
Posts: 926
|
lol i think i scared people away
![]() ![]()
__________________
![]() |
![]() |
![]() |
#3 |
Harper
![]() Join Date: October 2, 2001
Location: Aberdeen, Scotland
Age: 43
Posts: 4,774
|
(variable) << (file)?
Or does the file handle class have a read method? Ive never used files much in C++. Neatest way to do it would be to overload the << operator for your struct (which dosent neccesaerily mean turn it to a class, structs can have methods to) and just use the one call. But as long as it works youll get marks for it. |
![]() |
![]() |
#4 |
Takhisis Follower
![]() Join Date: April 30, 2001
Location: szép Magyarország (well not right now)
Posts: 5,089
|
Why don't you just set up file objects....the following example is from my old BG2 XP Patcher:
FILE *f = fopen("BGMain.exe","rb+wb"); FILE *f2 = fopen("VKXPPatcher.log","rb+wb"); fread(&d,8,1,f2); location = (int)d; fsetpos(f,&location); fread(&e,4,1,f); as you can see I open 2 files for binary read and binary write and then read into the address of the variable "d" 8 bits from the file f2. You can set the read position with fsetpos....those are C methods though, which would of course work in C++ but I guess you have to do it with C++ methods?
__________________
Too set in his ways to ever relate If he could set that aside, there'd be heaven to pay But weathered and aged, time swept him to grave Love conquers all? Damn, I'd say that area's gray |
![]() |
![]() |
#5 |
Harper
![]() Join Date: October 2, 2001
Location: Aberdeen, Scotland
Age: 43
Posts: 4,774
|
My previous post is embarassingly wrong. Use:
(file) >> (variable); instead. I need more C++ practice. What you get depends on what (variable) is. If its a BYTE you get one byte of data and have to write your own parser. Most versatile way of doing it, but hardly elegant.
__________________
[img]\"http://www.sighost.us/members/Zvijer/andrewas.gif\" alt=\" - \" /> |
![]() |
![]() |
#6 |
Emerald Dragon
![]() Join Date: March 12, 2001
Location: spokane wa usa
Age: 41
Posts: 926
|
well thanks for the replies, would have replyed earlier but the homework piles up quickly
![]() code://This Program was written by Chris Nance[/QUOTE]probably not elegant and it outputs a couple misalanious lines, and doesn't tell you if the input file is over 150 lines long but it works in the parameters, well except for telling you if the input is over 150 lines i was being lazy and thinking whail having a headach isn't the most conductive thing for programing. Just give me credit if you "borrow" the code or parts of it
__________________
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
a small question in regards to compression and files | Harkoliar | General Conversation Archives (11/2000 - 01/2005) | 10 | 11-26-2003 12:16 AM |
Need help with some MP3 files | Xen | General Conversation Archives (11/2000 - 01/2005) | 8 | 09-13-2003 05:51 AM |
IW should be on X-files. | Neb | General Conversation Archives (11/2000 - 01/2005) | 25 | 09-18-2001 04:47 PM |
EFF Files | Azred | Baldurs Gate II Archives | 0 | 06-10-2001 10:04 AM |
Help converting wac.files into wav.files? | t1d | Baldurs Gate II Archives | 6 | 05-23-2001 03:04 PM |