```cpp
#include<iostream>
#include<fstream>
using namespace std;
void test01() {
const char* fileName = "H:\\C++初级练习\\数据结构\\source.txt";
const char* targetName = "H:\\C++初级练习\\数据结构\\target.txt";
ifstream ism(fileName, ios::in);
ofstream osm(targetName, ios::out|ios::app);
if (!ism) {
cout << "打开文件失败!" << endl;
return;
}
char ch;
while (ism.get(ch)) {
cout << ch;
osm.put(ch);
}
ism.close();
osm.close();
}
class Person {
public:
Person(){}
Person(int age, int id) :age(age), id(id) {}
void show() {
cout << "Age:" << age << " id: " << id << endl;
}
public:
int age;
int id;
};
void test02() {
Person p1(10, 20), p2(30, 40);
const char* TargetName = "H:\\C++初级练习\\数据结构\\target.txt";
ofstream osm(TargetName, ios::out | ios::binary);
osm.write((char*)&p1, sizeof(Person));
osm.write((char*)&p2, sizeof(Person));
osm.close();
ifstream ism(TargetName, ios::in | ios::binary);
Person p3,p4;
ism.read((char*)&p3,sizeof(Person));
ism.read((char*)&p4, sizeof(Person));
p3.show();
p4.show();
}
int main(void) {
test02();
return 0;
}