473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

File Handeling Problem In C++

i cannot get the output by using the function showdata()........plz run this code and send the solution on my ID <ID removed by weaknessforcats>


// A PROGRAME TO OPERATE SOME FILE RELATED OPERATIONS....

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
class stock
{
public:
int no;
char mfd[10]; // DD/MM/YYYY
char exp[10]; // DD/MM/YYYY total 10 digits

};
void get()
{
clrscr();
stock stk;
cout<<"\n enter serial no : " ;
cin>>stk.no;
cout<<"\n enter mfd in DD:MM:YYYY formate : ";
cin>>stk.mfd;
cout<<"\n enter date of exp : ";
cin>>stk.exp;
ofstream fout;
fout.open("d:/stock.txt",ios::binary);
fout.seekp(ios::end);
fout.write((char*) &stk ,sizeof stk);
fout.close();
}
void showdata()
{
ifstream fin;
stock stk;
fin.open("d:/stock.txt",ios::binary);
fin.seekg(ios::beg);
fin.read((char *) &stk,sizeof stk);
cout<<"serial : "<<stk.no;
cout<<"\n mfd : "<<stk.mfd;
cout<<"\n exp : "<<stk.exp;
}


void main()
{
stock stk;
void get(void);
void showdata(void);
int choice;
cout<<"\n enter your choice :\n enter 1 for input and 2 for show data : ";
cin>>choice;
switch(choice)
{
case 1:
get();
break;
case 2:
showdata();
break;
}
getch();
}
Nov 28 '07 #1
2 1293
First of all i would ask you to see the Posting Guidelines.

Coming to the solution, do you really require a class for something that holds only data. You would be better off storing the data as a structure. Next, to support portability and easy retrieval, it would be better if you wrote each member separately into the file. The runtime may arrange each type differently and cause problems. Try writing(reading) each field separately and see the output.
Nov 28 '07 #2
First of all i would ask you to see the Posting Guidelines.

Coming to the solution, do you really require a class for something that holds only data. You would be better off storing the data as a structure. Next, to support portability and easy retrieval, it would be better if you wrote each member separately into the file. The runtime may arrange each type differently and cause problems. Try writing(reading) each field separately and see the output.








hello sir....thanks for giving reply..... i've assigned a project and this code is a part of that project(stock management system). i want to store the whole data in file through the object.bcz by using read and write functions i can easily retrive and save data to the file.......
so plz try to understand my problem and give the solution.
Nov 30 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
1
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
3
by: Kbalz | last post by:
I have a Form that is performing a wizard-like step system (using TabControl), and I need a key combination (like ControlKey + A + T) to be caught and show a secret admin TabPage. I tried to add...
1
tolkienarda
by: tolkienarda | last post by:
hello wonderful people of java land i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now...
1
by: ashruba | last post by:
I want to read inbox of nokia N72 through file handeling in c/c++ please give guidence.
9
by: shariquehabib | last post by:
Hi All, I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values. How can i do that..plz help me out....... E.g: file name...
4
by: shariquehabib | last post by:
Hi All, I am using file handeling in C lang. Can anyone please let me know that how can i read spaces from a perticular file?? To read some values (strings) i m using fscanf func. Can...
2
by: shariquehabib | last post by:
Hi, I am using C language to read a file: row.txt Can any one plz help me to get number of rows present in a file BEFORE reading a file. So i can check number of rows and if the rows greater...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.