1. 程式人生 > >將結構體數組中內容以文件形式的導出

將結構體數組中內容以文件形式的導出

res tac () end hda str phone nta 結構

void fileOutput(contacts student[] , int n){
  ofstream out ;
  out . open("tongxunlu-new.txt") ;
  for(int i = 0 ; i<= n-1 ; i++){
    out << "學號" << ‘\t‘ <<‘\t‘ << student[i].studentnum << ‘\n‘;
    out << "姓名" << ‘\t‘ <<‘\t‘ << student[i].name << ‘\n‘;
    out << "性別" << ‘\t‘ <<‘\t‘ << student[i].gender << ‘\n‘;
    out << "生日" << ‘\t‘ <<‘\t‘ << student[i].birthday.year <<"年"
               << student[i].birthday.month <<"月" 

               << student[i].birthday.day <<"日"

               << ‘\n‘;
    out << "家庭住址" << ‘\t‘ <<‘\t‘ << student[i].address << ‘\n‘;
    out << "QQ號" << ‘\t‘ <<‘\t‘ << student[i].qqnum << ‘\n‘;
    out << "電話號" << ‘\t‘ <<‘\t‘ << student[i].phonenum << ‘\n‘;
    out << "email" << ‘\t‘<<‘\t‘<< student[i].email << ‘\n‘<< ‘\n‘;

    }
  out.close();
  cout<<"導出文件成功"<<endl;
}

將結構體數組中內容以文件形式的導出