c++文件操作之二进制文件-读文件

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Person {
public:
    char name[64];
    int age;
};
void test() {
    ifstream ifs;
    ifs.open("person.txt", ios::in | ios::binary);
    if (!ifs.is_open()) {
        return;
    }
    Person p;
    ifs.read((char*)&p, sizeof(p));
    cout <<"p.name=" <<p.name <<","<<"p.age="<< p.age << endl;
    ifs.close();
}
int main() {
    test();
    system("pause");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/xiximayou/p/12103143.html