By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,201 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

problem with inputing all the values to file

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.