473,396 Members | 1,915 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,396 software developers and data experts.

problem with inputing all the values to file

EmployeeTable<Employee> employees;//where EmployeeTable is the array
that stores the employees
PositionIndex<EmployeeString>employee_nameIndex;//index for the
array by last name and first name
for( int i = 0; i < 3; i++ )
{
cout << "Enter Employee info:" << endl;
Employee employee;
cin >> employee;
employees.push_back( employee );
Pair<EmployeeString, unsigned long> nameIndexEntry(
employee.getNameKey(), i );
employee_nameIndex.push_back( nameIndexEntry );
}
// sort index
employee_nameIndex.sort();

// search for employee by name
char s = 0;
EmployeeString firstName;
EmployeeString lastName;
EmployeeString ssn;
cout << "Search for Employee: " << endl;
do
{
cout << "First name:";
cin >> firstName;
cout << "\nLast name:";
cin >> lastName;
cout << "\nSSN:";
cin >> ssn;
long pos = employee_nameIndex.search( lastName + firstName +ssn
);
if ( pos < 0 )
{
cout << "Employee NOT found" << endl;
}
else
{
cout << "employee found: " << endl;
cout << employees[pos];
}
cout << "Search another employee(y/n)?" << endl;
s = getch();
}while( s != 'n' );
ofstream of;
cout << "Save following Employee to Employees.dat" << endl;
cout << employees;
of.open( "employees.dat", ios_base::binary );
of << employees;
of.close();
EmployeeTable<Employee> employeesIn;
ifstream inf;
inf.open( "employees.dat", ios_base::binary );
inf >> employeesIn;
inf.close();
inf.seekg(0);
cout << "Following is Employees from employees.dat" << endl;
cout << employeesIn;
}

My array is overwritting on previous records, every time i enter values
into the record.
Please help
Kelly

Jul 22 '05 #1
10 1458
Kelly wrote:
[...]
My array is overwritting on previous records, every time i enter values
into the record.
Please help


This is FAQ 5.8.

My old teacher of theoretical mechanics used to say that a good drawing,
scheme, picture, illustration, gives 50% of a solution to the problem.
The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

Take the time to read the FAQ and follow its instructions.

V
Jul 22 '05 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:uDlyd.12564
The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

V


Hi Victor,

you know, it may be that the code is indented fine in his editor. On my
PC, if I indent using tabs, my Outlook Express software removes them when I
post to here. I have to explicitly use spaces in my code in order to get
indentation to show up. So what I'm saying is, maybe we shouldn't jump on
everyone who posts code that looks like it's not indented...it could just be
their newsreader that screws it up!

-Howard

Jul 22 '05 #3
Howard wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:uDlyd.12564

The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

V

Hi Victor,

you know, it may be that the code is indented fine in his editor. On my
PC, if I indent using tabs, my Outlook Express software removes them when I
post to here. I have to explicitly use spaces in my code in order to get
indentation to show up. So what I'm saying is, maybe we shouldn't jump on
everyone who posts code that looks like it's not indented...it could just be
their newsreader that screws it up!


Hi Howard,

You know, it may be that the OP is using such a bad newsreader that they
won't be able to ever post the code well-indented. I can live with that.
But when it's not just not indented but also incomplete and not even
described well, you will have to excuse me. So what I'm saying is, maybe
you will not jump on _me_ for trying to educate newbies how to post in
comp.lang.c++...
Jul 22 '05 #4

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:wj*****************@newsread1.dllstx09.us.to. verio.net...
Howard wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:uDlyd.12564

The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

V

Hi Victor,

you know, it may be that the code is indented fine in his editor. On
my PC, if I indent using tabs, my Outlook Express software removes them
when I post to here. I have to explicitly use spaces in my code in order
to get indentation to show up. So what I'm saying is, maybe we shouldn't
jump on everyone who posts code that looks like it's not indented...it
could just be their newsreader that screws it up!


Hi Howard,

You know, it may be that the OP is using such a bad newsreader that they
won't be able to ever post the code well-indented. I can live with that.
But when it's not just not indented but also incomplete and not even
described well, you will have to excuse me. So what I'm saying is, maybe
you will not jump on _me_ for trying to educate newbies how to post in
comp.lang.c++...


Sorry, Victor, didn't mean to jump on you. It's just that every time
someone posts unindented code, they get jumped on, and I wanted to suggest
easing up on that particular subject a little. (By the way, I did like your
use of my phrasing to reply back to me...very creative! :-))

-H

Jul 22 '05 #5
If your example example is the sequence of your code, then you need to read
from the file first, let the "user" enter employees, and then save to a
file.

In your sample you let the user enter some data, then saves to file, and
then read from the file. Your data will be overwritten...

Jesper
Jul 22 '05 #6
On 22 Dec 2004 13:07:10 -0800 in comp.lang.c++, "Kelly"
<vk******@yahoo.com> wrote,
My array is overwritting on previous records, every time i enter values
into the record.


Cannot tell from your code if you are even reading employee record
successfully, or doing so more than once. Consider something more
like

cout << "Enter Employee info:" << '\n'; // eschew endl
Employee employee;
while (cin >> employee) {
cout << i++ << ": " << employee << '\n';
// do stuff with it...

This issue is covered in Marshall Cline's C++ FAQ. See section 15,
especially the topic "[15.6] Why is my program ignoring my input
request after the first iteration?" It is always good to check the
FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

Jul 22 '05 #7
Howard wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:uDlyd.12564

The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

V
you know, it may be that the code is indented fine in his editor. On my
PC, if I indent using tabs, my Outlook Express software removes them when I
post to here.


Either don't use Outlook Express or use spaces. Most editors offer an
option to convert some text from tabs to spaces.
I have to explicitly use spaces in my code in order to get
indentation to show up.
Is that so bad for some free help?
So what I'm saying is, maybe we shouldn't jump on
everyone who posts code that looks like it's not indented...it could just be
their newsreader that screws it up!


Maybe people should learn to use their newsreader first.
Jonathan
Jul 22 '05 #8
Howard wrote:
[snip] you know, it may be that the code is indented fine in his editor. On my
PC, if I indent using tabs, my Outlook Express software removes them when I
post to here. I have to explicitly use spaces in my code


.... which is a good idea anyway, since there is no standard on the stop
points of one tab. 8 is common but can usually in todays editors be reset
to anything you want. If you ever get a source code from someone whoes tab
definition does not match yours, you will execrate the inventor of tab.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #9

"Jonathan Mcdougall" <jo***************@DELyahoo.ca> wrote in message
news:1N*********************@weber.videotron.net.. .
Howard wrote:
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:uDlyd.12564

The code you posted (I couldn't even force myself to keep it quoted) is
so badly organized (whitespace-wise, indentation-wise, comments), nobody,
including yourself, can find the ends of the issue in it without first
reformatting and reindenting the whole thing. Besides, it's incomplete.

V
you know, it may be that the code is indented fine in his editor. On
my PC, if I indent using tabs, my Outlook Express software removes them
when I post to here.


Either don't use Outlook Express or use spaces. Most editors offer an
option to convert some text from tabs to spaces.


I DO use spaces, as I said below! (I have had jobs, however, where the use
of tabs in code was required. And it's hardly your place to tell me what
software to use. OE is the most common newsreader in the world, I'd bet.)
I have to explicitly use spaces in my code in order to get
indentation to show up.
Is that so bad for some free help?


Who said it's bad? I do it all the time now. I simply suggested that the
REASON that many posts come with no indentation MAY be that they use a
newsreader that stripped their tabs.
So what I'm saying is, maybe we shouldn't jump on
everyone who posts code that looks like it's not indented...it could just
be their newsreader that screws it up!


Maybe people should learn to use their newsreader first.


What a lovely, generous attitude. All I'm suggesting is a little tolerance
for posters whose code shows up unindented. Maybe a polite "you might want
to use spaces instead of tabs, because this is unreadable", or something
similar. Is tolerance so hard, or so evil?

Merry Christmas!
Jul 22 '05 #10
Howard wrote:
[steamed up response removed] Is tolerance so hard, or so evil?


So, when are you going to show some tolerance?
Jul 22 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David ©tefić | last post by:
could someone please write the code for read out of the database... here is my input code: $Host = "localhost"; $User = "david"; $Password = "david"; $DBName = "hej"; $TableName = "text";
2
by: altergothen | last post by:
Hi there I am a newbie to ASP.Net - Please Help! I am trying to insert the values of my variables into a database. If I try the following it works perfectly: string insertQuery = "INSERT into...
0
by: sos | last post by:
I am new to VBasic - I understand that forms are used to enter data, but it would be nice for the person entering to see some summarizing information derived from all inputted data on the screen...
1
by: Icarus27 | last post by:
I am having another problem. I got the first problem fixed and it is working almost right but when I import the information it doesn't pick up the information for the fourth array. Here is the...
2
by: genti1 | last post by:
Hi, I am kind of new with Access and I was wandering if someone could help me create a form where I can query data in a table by entering values in that form. For Example: I have a table...
2
by: beepa | last post by:
As you will be able to see I am fairly new at this. Here is the part I'm having problems figuring out: The file I'm inputing from is formated like this: firstName lastName postion name (one or...
1
by: mimranp | last post by:
hi all i want to escape starting ('' )at the start of string i want to just replace the string <%@ WebHandler Language="C#" Class="Type_BLC" %> using System; using System.Web; using...
7
by: kenrocks | last post by:
i have 2 classes 1 main with methods and a gui file on the mainfile I have an aDD method. public void aDD(JTextField a, String r) { int x=0; while(x<r.length) { ...
4
by: zbych | last post by:
Hello everyone I have a problem with this application in Access. Application itself is supposed to help users controling parts production. The steps when using form: Step 1. This specific...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.