文件操作
# C 语言文件操作
FILE* fopen(
_In_z_ char const* _FileName,
_In_z_ char const* _Mode
);
errno_t __cdecl fopen_s(
_Outptr_result_maybenull_ FILE** _Stream,
_In_z_ char const* _FileName,
_In_z_ char const* _Mode
);
size_t __cdecl fwrite(
_In_reads_bytes_(_ElementSize * _ElementCount) void const* _Buffer,
_In_ size_t _ElementSize,
_In_ size_t _ElementCount,
_Inout_ FILE* _Stream
);
// 文件偏移到指定位置
fseek(
_Inout_ FILE* _Stream, //指向FILE结构体指针
_In_ long _Offset, //偏移量
_In_ int _Origin//指定文件指针的起始位置 //SEEK_CUR 当前位置 //SEEK_END 文件结尾位置 SEEK_SET 文件开始位置
);
ftell 返回文件指针的当前位置
fread 返回值表示当前读文件到缓冲区的大小
# C++ 文件操作
#include <io.h>
#include <fstream>
ofstream 类 (const char* _Filename, ios_base::openmode _Mode = ios_base::out, int _Prot = ios_base::_Default_open_prot)
// 读文件
ifstream ifs("2.txt");
char pBuf[100] = { 0 };
ifs.read(pBuf, 100);
ifs.close();
USES_CONVERSION;
CString strBuf = A2W(pBuf);
MessageBox(strBuf);
// 写文件
ofstream ofs("2.txt");//第一个参数表示文件名,2 打开的方式,
ofs.write("BingoC++", strlen("BingoC++"));
ofs.close();