| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 420 人关注过本帖
标题:信息管理
取消只看楼主 加入收藏
王文倩
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-4-23
结帖率:0
收藏
已结贴  问题点数:10 回复次数:0 
信息管理
#include<iostream>
#include<fstream>
using namespace std;
struct staff
{
    int num;
    char name[20];
    int age;
    double pay;
};
int main()
{
    staff staff[7]={2101,"li",34,1203,2104,"wang",23,674.5,2108,"fun",54,778,3006,"xue",45,476.5,5101,"ling",39,656.6
    },staff1;
    fstream iofile("staff.dat",ios::in|ios::out|ios::binary);
    if(!iofile)
    {
        cerr<<"open staff.dat error!"<<endl;
        exit(1);
    }
    int i,m,num;
    cout<<"Five staff:"<<endl;
    for(i=0;i<5;i++)
    {
        cout<<staff[i].num<<staff[i].name<<staff[i].age<<staff[i].pay<<endl;
        iofile.write((char *)&staff[i],sizeof(staff[i]));
    }
    cout<<"Please input data you want insert:"<<endl;
    iofile.seekp(0,ios::end);
    for(i=0;i<2;i++)
    {
        cin>>staff1.num>>staff1.name>>staff1.age>>staff1.pay;
        iofile.write((char *)&staff1,sizeof(staff1));
    }
    cout<<"Senven staff:"<<endl;
    iofile.seekg(0,ios::beg);
    for(i=0;i<7;i++)
    {
        iofile.read((char *)&staff[i],sizeof(staff[i]));
        cout<<staff[i].num<<staff[i].name<<staff[i].age<<staff[i].pay<<endl;
    }
    bool find;
    cout<<"enter number you want search ,enter 0 to stop"<<endl;

    cin>>num;
    while(num)
    {
        find=false;
        iofile.seekg(0,ios::beg);
        for(i=0;i<7;i++)
        {
            iofile.read((char *)&staff[i],sizeof(staff[i]));
            if(num==staff[i].num)
            {
                m=iofile.tellg();
                cout<<num<<"is No."<<m/sizeof(staff1)<<endl;
                cout<<staff[i].num<<""<<staff[i].name<<""<<staff[i].age<<""<<staff[i].pay<<endl;
                find=true;
                break;
            }
        }
        if(!find)
        cout<<"cant't find"<<num<<endl;
        cout<<"enter number you want search,enter 0 to stop.";
        cin>>num;
    }
    iofile.close();
    return 0;
}
为什么老是出现
open staff.dat error!
Press any key to continue一直解决不了,求帮忙
搜索更多相关主题的帖子: include 信息 double 
2013-06-13 09:28
快速回复:信息管理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012058 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved