将所有值输入到文件的问题 [英] problem with inputing all the values to file

查看:49
本文介绍了将所有值输入到文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EmployeeTable中<员工> employees; //其中EmployeeTable是数组

存储员工

PositionIndex< EmployeeString> employee_nameIndex; //

数组的索引姓氏和名字

for(int i = 0; i< 3; i ++)

{

cout<< 输入员工信息: << endl;

员工员工;

cin>>员工;

employees.push_back(员工);

配对< EmployeeString,unsigned long> nameIndexEntry(

employee.getNameKey(),i);

employee_nameIndex.push_back(nameIndexEntry);

}

//排序索引

employee_nameIndex.sort();


//按名称搜索员工

char s = 0 ;

EmployeeString firstName;

EmployeeString lastName;

EmployeeString ssn;

cout<< 搜索员工: << endl;

do

{

cout<< 名字:" ;;

cin>> firstName;

cout<< " \\\
Last name:";

cin>> lastName;

cout<< \ nSSN:" ;;

cin>> ssn;

long pos = employee_nameIndex.search(lastName + firstName + ssn

);

if(pos< 0)

{

cout<< 未找到员工 <<结束;

}

其他

{

cout<< 员工发现: << endl;

cout<<员工[pos];

}

cout<< 搜索其他员工(是/否)? << endl;

s = getch();

} while(s!=''n'');

ofstream;

cout<< 将以下员工保存到Employees.dat << endl;

cout<<员工;

of.open(" employees.dat",ios_base :: binary);

of<<员工;

of.close();

EmployeeTable< Employee> employeesIn;

ifstream inf;

inf.open(" employees.dat",ios_base :: binary);

inf>> ; employeesIn;

inf.close();

inf.seekg(0);

cout<< 以下是employees.dat的雇员 << endl;

cout<< employeesIn;

}


每次我在记录中输入值

时,我的数组会覆盖以前的记录。 />
请帮助

Kelly

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

推荐答案

Kelly写道:
[...]
每次我在记录中输入值
时,我的数组都会覆盖以前的记录。
请帮忙
[...]
My array is overwritting on previous records, every time i enter values
into the record.
Please help



这是FAQ 5.8。


我的理论力学老师曾经说过一个好的绘画,

计划,图片,插图,提供50%的问题解决方案。

您发布的代码(我甚至无法强迫自己保持引用)是

如此糟糕的组织(空白) -wise,缩进方式,评论),没人,

包括你自己,可以在没有首先找到问题的结尾

重新格式化和重新定义整个事情。此外,它还不完整。


花时间阅读常见问题解答并按照说明操作。


V



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




" Victor Bazarov" <五******** @ comAcast.net>在消息新闻中写道:uDlyd.12564

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:uDlyd.12564
你发布的代码(我甚至不能强迫自己保持引用)是如此糟糕的组织(空白方面) ,缩进,评论),没有人,包括你自己,可以在没有首先重新格式化和重新整理整个事情的情况下找到问题的目的。此外,它还不完整。

V
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




你好Victor,


你知道吗,可能是代码在他的编辑器中缩进了。在我的

PC上,如果我缩进使用标签,我的Outlook Express软件会在我发布到此处时将其删除。我必须在我的代码中明确使用空格才能显示

缩进。所以我要说的是,也许我们不应该跳上

每个发布代码看起来都没有缩进的人...它可能只是

他们的新闻阅读器搞砸了!


-Howard



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


Howard写道:
Victor Bazarov <五******** @ comAcast.net>在消息新闻中写道:uDlyd.12564

"Victor Bazarov" <v.********@comAcast.net> wrote in message news:uDlyd.12564

你发布的代码(我甚至无法强迫自己引用它)是如此糟糕的组织(空白,缩进,评论),没有人,包括你自己,可以在没有首先重新格式化和重新整理整个事物的情况下找到问题的目的。此外,它还不完整。

V
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



你好Victor,

你知道,可能代码是在他的编辑中缩进了。在我的
PC上,如果我缩进使用标签,我的Outlook Express软件会在我发布到此处时删除它们。我必须在代码中明确使用空格才能显示缩进。所以我要说的是,也许我们不应该跳过
每个发布代码看起来都没有缩进的人......它可能就是他们的新闻阅读器搞砸了它up!


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,


你知道,可能OP正在使用这样一个糟糕的新闻阅读器他们

将无法以良好的方式发布代码。我可以忍受这个。

但是当它不仅没有缩进但也不完整而且甚至没有描述好b / b时,你将不得不原谅我。所以我要说的是,也许

你不会跳过_me_试图教育新手如何发表

comp.lang.c ++ ...



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++...


这篇关于将所有值输入到文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆