C++DAY45


#include 
#include 
#include 
using namespace std;

class Stu
{
public:
    string name;
public:
    Stu(){}
    Stu(string n):name(n){}

};

ostream &operator <<(ostream &cout,const Stu &s)
{
    cout << s.name << endl;
    return cout;
}

int main()
{

    Stu s1("zhangsan");
    Stu s2("lisi");
    Stu s3("wangwu");

    vector  s;
    s.push_back(s1);
    s.push_back(s2);
    s.push_back(s3);

    ofstream ofs;
    //打开文件
    ofs.open("D:/Download/new/qt/1/stu.txt",ios::out);
    vector::iterator iter;
    for(iter=s.begin();iter!=s.end();iter++)
    {
        ofs << *iter;
    }
    ofs.close();

    ifstream ifs;
    ifs.open("D:/Download/new/qt/1/stu.txt",ios::in);
    char buf[1024];
    vector ::iterator it;
    while(ifs >> buf)
    {
        for(it=s.begin();it!=s.end();it++)
        {
            cout << *it;
        }
        cout << endl;
    }
    ifs.close();

    return 0;
}

 

你可能感兴趣的:(c++,开发语言)