#include <iostream>
#include <fstream>
using namespace std;
struct Work
{
int num;
char name[20];
char tele[20];
} w;
int main()
{
int i;
ofstream foutput;
foutput.open("d:\\1.txt");
if (foutput.fail( )) //如果打开文件失败所出现的情况
{
cout<<"open file error!\n";
}
for (i=0;i<1; i++)
{
cout<<"请输入员工的编号、姓名和电话:\n";
cin>>w.num>>w.name>>w.tele;
foutput<<w.num<<endl<<w.name<<endl<<w.tele<<endl;
}
foutput.close();
ifstream finput;
finput.open("d:\\1.txt");
if (finput.fail())
{
cout<<"open file error!\n";
}
while (finput>>w.num>>w.name/*>>w.tele*/) //读入文件中的内容
{
cout<<"该员工的编号为:"<<w.num<<endl
<<"该员工的姓名为:"<<w.name<<endl
<<"该员工的电话为:"<<w.tele<<endl;
}
finput.close();
return 0;
}
原文链接: https://www.cnblogs.com/tcxuxinlong/archive/2012/10/09/2716026.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/65226
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!