| | |
binary file into class using dynamic arrays
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 2
Reputation:
Solved Threads: 0
i hace a class in c++ bcw
i need a function that fills a Student type dynamic array from a bin file called binfile1.dta the array starts with size[30]. And then do the same for another file binfile2.dta to fill a dynamic array student type char mathid[10] the array starts with size[5].when an array wants more memory it must renew it self and ask more space.
can anybody help me ?
the binfile1.dta has data for sIdNum,sSurname,sFirstname
the binfile2.dta has data for mathid (math id is like XX000 XX001 etc in lines )
C++ Syntax (Toggle Plain Text)
class Student { public: private: unsigned int sIdNum; char sSurname[20]; char sFirstname[20]; char mathid[10]; };//Student
i need a function that fills a Student type dynamic array from a bin file called binfile1.dta the array starts with size[30]. And then do the same for another file binfile2.dta to fill a dynamic array student type char mathid[10] the array starts with size[5].when an array wants more memory it must renew it self and ask more space.
can anybody help me ?
the binfile1.dta has data for sIdNum,sSurname,sFirstname
the binfile2.dta has data for mathid (math id is like XX000 XX001 etc in lines )
>can anybody help me ?
If by "help" you mean "write it for me", no. Nobody will help you. If you mean help in the more traditional sense of you do the majority of the work and we give you hints and tips, and suggest ways to improve your solution, yes. We'll be happy to help. But as it is, you don't have any code and haven't told us how you plan to write this function, so there's nothing to help with.
If by "help" you mean "write it for me", no. Nobody will help you. If you mean help in the more traditional sense of you do the majority of the work and we give you hints and tips, and suggest ways to improve your solution, yes. We'll be happy to help. But as it is, you don't have any code and haven't told us how you plan to write this function, so there's nothing to help with.
I'm here to prove you wrong.
>>mathid[10] the array starts with size[5].when an array wants more memory it must renew it self and ask more space.
You can't dynamically expand the array size when it is statically allocated like you posted in the class. You will have to make mathid a pointer if you want to change its size at runtime.
Or better yet, since this is a c++ program using std::string instead of character arrays. The string class will do all the messary memory allocations for you, simplifying your whole program.
You can't dynamically expand the array size when it is statically allocated like you posted in the class. You will have to make mathid a pointer if you want to change its size at runtime.
Or better yet, since this is a c++ program using std::string instead of character arrays. The string class will do all the messary memory allocations for you, simplifying your whole program.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
If that file contains variable length strings then you can not read it with just one read statement. You will have to devise a more complex algorithm to read the file. Exactly what algorithm depends on the file's contents, that is, how was that file written.
Last edited by Ancient Dragon; Oct 11th, 2007 at 9:42 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Reading a Binary file using Visual Basic (Visual Basic 4 / 5 / 6)
- Reading a Binary File to a C++ Class (C++)
- Creating dynamic arrays (C++)
- Reading an input file as a class memeber function (C++)
- Question about debugging .class file (Java)
- binary tree class (C++)
- binary file manipulations (C)
- How to load binary content of a .class file? (Java)
- C++ raster files (writing structs to a binary file) (C++)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






