程序片断
CString m_code,m_path;
//读取ini文件
GetPrivateProfileString("Config","Code","",m_code.GetBuffer(MAX_PATH),MAX_PATH,".\\config.ini"); //提示取出的数据
AfxMessageBox(m_code); // 设置保存外部的文件路径
m_path = "c:\\1.txt";
//创建文件
HANDLE hFile = CreateFile(m_path,GENERIC_READ|GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

DWORD dwBytes;
//要写的字符串
CString m_txtStr;
//将要写的内容复制给变量
m_txtStr = m_code;
//写文件
WriteFile(hFile,(LPCVOID)(LPCTSTR)m_txtStr,m_txtStr.GetLength(),&dwBytes,FALSE);
//关闭文件
CloseHandle(hFile);