理解CFile类
CFile类是MFC独有的输入输出类,如同C++中的文件流类fstream,其工作原理是相同的。不同点在于CFile类定义的对象既是输入也是输出对象,而C++中是ofstream类定义输出对象,ifstream类定义输入对象。
使用CFile类输出到文本文件中
1、CFile类定义对象
CFile fout;
2、调用打开open()函数
CString FileName = _T("A:\\student.txt");
fout.Open(FileName, CFile::modeCreate|CFile::modeWrite);
3、调用写入write()函数
fout.Write(sno,strlen(sno));//此处要修改字符集模式为多字节字符集才行
4、调用关闭close()函数
fout.Close();
CString FileName = _T("A:\\student.txt");
CFile fout;
fout.Open(FileName, CFile::modeCreate|CFile::modeWrite);
fout.Write(sno,strlen(sno));
fout.Close();