Is binary file I/O necessary? It seems much more logical with text mode reading into std::strings.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct rec
{
string name;
string phone;
};
istream& operator>>(istream& i, rec& record)
{
i >> record.name
>> record.phone;
return i;
}
ostream& operator<<(ostream& o, rec& record)
{
o << record.name << " " << record.phone
<< "\n" << record.name
<< "\n" << record.phone << "\n";
return o;
}
int main()
{
rec record1,
record2,
record3;
ifstream infile;
infile.open("C:\\a.txt", ios::in);
infile >> record1 >> record2 >> record3;
cout
<< record1 << "\n"
<< record2 << "\n"
<< record3 << "\n";
infile.close();
}