首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

何输出存在文本中的结构体,该如何解决

2012-02-28 
何输出存在文本中的结构体请问如何输出存在文本中的结构体?如下面这个程序,如何输出?#includestdio.h#in

何输出存在文本中的结构体
请问如何输出存在文本中的结构体?
如下面这个程序,如何输出?
#include   <stdio.h>
#include   <stdlib.h>
#include   <iostream.h>
#include   <fstream.h>
#define   N   10  
struct   user
              {
char   name[20];
char   sex;
        long   id;
long   num;
float   mon;
                }   user[N],max;
void   main(void)
{     ifstream   file;
      file.open( "data.txt ");      
                cout < < "请输入数据! " < <endl;
                ofstream   ofile;
                ofile.open( "data.txt ");
cout < < "姓名: "   ;
                cin> > user[0].name;
                ofile < <user[0].name;
cout < < "性别: ";
cin> > user[0].sex;
                ofile < <user[0].sex;
cout < < "身份证号: ";
cin> > user[0].id;
                ofile < <user[0].id;
cout < < "银行卡号: ";
cin> > user[0].num;
                ofile < <user[0].num;
cout < < "现金总额: ";
cin> > user[0].mon;
                ofile < <user[0].mon;
                file.close();  
          file.open( "data.txt ");


[解决办法]
void main(void)
{
ofstream ofile;
ofile.open( "data.txt ");

cout < < "请输入数据! " < <endl;
cout < < "姓名: " ;
cin> > user[0].name;
ofile < <user[0].name < < " ";

cout < < "性别: ";
cin> > user[0].sex;
ofile < <user[0].sex < < " ";

cout < < "身份证号: ";
cin> > user[0].id;
ofile < <user[0].id < < " ";

cout < < "银行卡号: ";
cin> > user[0].num;
ofile < <user[0].num < < " ";

cout < < "现金总额: ";
cin> > user[0].mon;
ofile < <user[0].mon < < " ";

ofile.close();

ifstream ifile;
ifile.open( "data.txt ");

ifile> > user[1].name;
ifile> > user[1].sex;
ifile> > user[1].id;
ifile> > user[1].num;
ifile> > user[1].mon;

ifile.close();


cout < < "姓名: " < <user[1].name < <endl ;
cout < < "性别: " < <user[1].sex < <endl;
cout < < "身份证号: " < <user[1].id < <endl;
cout < < "银行卡号: " < <user[1].num < <endl;
cout < < "现金总额: " < <user[1].mon < <endl;


}

热点排行