![]() |
Write and read data to/from File
:):)i 'm doing my assignment but i have some problem with this.can anyone help me to solve this problem .
here is my code: Code:
#include<fstream.h> |
Re: Write and read data to/from File
Can you let me know what is the problem that you got ..
|
Re: Write and read data to/from File
i want to write a program that can let user input the data in the function call "reg" as show at below:
Code:
void reg()when the user want to display out the data that user input, the program can automatic read from the file "student_details.txt" and it will show the data in the screen with the function "dpl". Code:
void dpl() |
Re: Write and read data to/from File
Is the problem is entering into the file or displaying from the file?
|
Re: Write and read data to/from File
In the code which you menctioned in 1st post as far as understand
1. in case1 of smenu() first you are asking the user " wish to add more data". if the user selected Y then again u r calling reg(), so that time all your previous data will be lost as the i value will be agian 1.. and it will try to store in std[1].. so only last record will be saved.. Better to initiliaze the value of 'i' in constructor.. or else instead of saving all the students valus at a time you can save one student details into the file and ask for another student details and save it at that time there is no need to take the array and you can save lot of memory.. 2. To read instead of while( toread ) use while ( !toread.eof() ) so that you will know whether the file is reached end of file or not.. otherwise all the time it will be true and will continue forever.. and toread.read((char*)&st,sizeof(student)); is not correct.. as when you read from a file you will get a string.. it won't store in a structure.. so you won't get the correct o/p it seams.. and also here you are using st.. but in dpl() it is member variable std.. which contains last students records not the one which you are reading.. |
| All times are GMT +5.5. The time now is 03:53. |