请问我这样写入正确吗? 我想把它输出到屏幕怎么做?谢谢

#include
#include
#include
using namespace std;
struct student{
string name;
int age;
};
void main(){
student s[2]={{"dl",19},{"yyl",20}};
string name="测试.txt";
ofstream out(name,ios::binary);
out.write((char *)s,sizeof(student)*2);
out.close();
ifstream in(name,ios::binary);

in.close();
system("pause");

}

std::cout代替你的out就可输出到屏幕

 struct student
{
    string name;
    int age;
};
void main()
{
    student s[]={{"dl",19},{"yyl",20}};
    student s1[2];
    string name = "123.txt";
    ofstream out(name.c_str(),ios::in);
    out.write((char *)s,sizeof(student) * 2);
    out.close();

    ifstream in(name.c_str(),ios::out); 
    in.read((char *)s1,sizeof(student) * 2);
    cout << s1[0].name << s1[0].age <<endl;
    cout << s1[1].name << s1[1].age <<endl;
    in.close();
    system("pause");
}