Files
BasicsOfComputerSoftwareEng…/OOP/2015Exam/3.3.cpp
2023-05-30 19:29:48 +08:00

21 lines
529 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <fstream>
#include <iostream>
using namespace std;
int main() { // 说明在VS2008编译系统上ios_base::与ios::功能相同
int dd[] = {1, 2, 3, 4, 5};
ofstream f1("data1.dat", ios_base::binary);
f1.write((char *)dd, sizeof(dd));
f1.close();
ifstream f2("data1.dat", ios_base::binary);
f2.seekg(sizeof(int) * 1, ios::beg);
f2.read((char*) &dd[0], sizeof(int) * 2);
f2.close();
for (int k = 0; k < 4; k++) {
cout << dd[k] << ',';
}
return 0;
}
/*
2,3,3,4,
*/