#include<iostream>
using namespace std;
#include<stdio.h>
#include<windows.h>
FILE* stream;
errno_t err;
int open()
{
if ((err = (fopen_s(&stream, "d:/text.txt", "rb")) != 0))
cout << "filed open" << endl;
return -1;
}
else {
return 0;
}
}
int open1()
{
if ((err = (fopen_s(&stream, "d:/text.txt", "ab")) != 0)) {
cout << "filed open" << endl;
return -1;
}
else {
return 0;
}
}
struct Student
{
int id;
char name[12];
char sex[4];
};
int save()
{
char buf[12];
Student hd{ 13,"hdd","man" };
open1();
fwrite(&hd.id, 1, 1, stream);
fwrite(&hd.name, 1, 12, stream);
fwrite(&hd.sex, 1, 4, stream);
_fcloseall();
return 0;
}
int load()
{
open();
char buf[4];
while (!feof(stream))
{
int n = fread(buf, 1, 4, stream);
if (n > 0) {
cout << "read" << n << " bytes" << endl;
for (int i = 0; i < 4; i++){
cout << hex<<" " << (int)buf[i] ;
}
}
}
return 0;
}
int main()
{
save();
DOWRD dwStart=GetTickCount();
load();
DWORD dwEnd=GetTickCount();
cout<<"time suing"<<dwEnd-dwStart<<endl;
cout << " eqqual "<< dec <<ftell(stream) << endl;
_fcloseall();
return 0;
}