百度09年校园招聘交大考点的一道题

来源:互联网 发布:阿里云学生机怎么用 编辑:程序博客网 时间:2024/04/30 20:38

找出下面程序中的错误,并改正:

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

class Test

{

public:

      string s;

};

main()

{

  Test *t=new Test[3];

  ofstream output("file",ofstream::binary);

  t[0].s="hello";

  t[1].s="World";

  t[2].s="!";

  output.write((char*)t,3*sizeof(Test));

  output.close();

  delete[] t;

  ifstream input("file",ifstream::binary);

  Test in[3];

  input.read((char*)t,3*sizeof(Test)):

  input.close();

  cout<<in[0].s<<in[1].s<<in[2].s<<endl;

 return 0;

}

//ofstream::binary和ifstream::binary表示已二进制形式进行读写

原创粉丝点击