#include <fstream>
#include <iostream>
#include <string>
using namespace std;
struct Person{
    string name;
    int age;
    double salary;
};
ofstream& operator<<(ofstream &fout,const Person &p){
    fout << p.name << "\n"  << p.age <<"\n" << p.salary << "\n";
    return fout;
}
ifstream& operator>>(ifstream &fin,Person &p){
    fin >> p.name >> p.age >> p.salary;
    return fin;
}
void writeData(){
    ofstream fout("d:/test.b");
    for(int i = 0;i < 20; ++i){
        Person p;
        p.name = "superman";
        p.age = i * 2;
        p.salary = i * 3.0;
        fout << p;
    }
    fout.close();
}
void readData(){
    ifstream fin("d:/test.b");
    Person p;
    while(fin >> p){
        cout << p.name << ","<< p.age << "," << p.salary << endl;
    }
    fin.close();
}
int main(int argc, char *argv[])
{
    writeData();
    readData();
    system("pause");
}
	
 
pic

此主题相关图片如下:snap6.png
	[此贴子已经被作者于2014/6/15 22:53:39编辑过]
 
portfo

此主题相关图片如下:qq截图20140623090237.png

lio
[此贴子已经被作者于2014/6/23 9:05:41编辑过]