打印到txt的代码是在csdn看到的,输出表头是我加的,,但是在加完表头后,就会报heap corruption detected,这个错误,大侠路过看看-----CString   strFileName; 
CFileDialog   m_ldFile(FALSE); 
    m_ldFile.m_ofn.lpstrFilter   =   "*.TXT "; 
m_ldFile.m_ofn.lpstrDefExt   =   "TXT ";  if   (m_ldFile.DoModal()   ==   IDOK) 

strFileName   =   m_ldFile.GetPathName();       //包括了路径和文件名 
} //创建文件 
char*   pszFileName   =   strFileName.GetBuffer(strFileName.GetLength());
CStdioFile   myFile; 
CFileException   fileException;  if   (!myFile.Open(   pszFileName,   CFile::modeCreate | CFile::modeWrite   ), &fileException ) 

TRACE(   "Can 't   open   file   %s,   error   =   %u\n ", 
pszFileName,   fileException.m_cause   ); 
     } 
 
//文件中写入内容 
 CString list[]={                                   //这里,,是我加的
"学号","姓名","课程名","日期","节次","刷卡时间"};
int i = 0;
for(int i=0;i<6;i++)
{
if(i==5)
{
  lstrcat(list[i].GetBuffer(list[i].GetLength()), "\n "); 
}
else
{
lstrcat(list[i].GetBuffer(list[i].GetLength()), "\t ");  }
   myFile.WriteString(list[i].GetBuffer(list[i].GetLength())); 
}                                                                          //到这里,加完后虽然写进文件,但是就会报错啊
 

int   iColSum   =  6;       //List中的栏数 
int   iCount   =   m_list.GetItemCount(); 
        
for   (int   iItem   =   0;   iItem   <   iCount;   iItem++) 
for   (int   iCol   =   0;   iCol   <   iColSum;   iCol++) 

CString   strTemp   =   m_list.GetItemText(   iItem,   iCol);  if   (iCol   ==   5)
lstrcat(strTemp.GetBuffer(strTemp.GetLength()),   "\n "); 
else 
lstrcat(strTemp.GetBuffer(strTemp.GetLength()),   "\t");  myFile.WriteString(strTemp.GetBuffer(strTemp.GetLength()));     } 

   
//是否立即查看该文件 
if   (MessageBox( "已保存,要查看吗 ",   "完成 ",   MB_YESNO)   ==   IDYES) 

ShellExecute(NULL,   
"open ",   
pszFileName,   
NULL,   
NULL,   
SW_SHOWNORMAL); 
} //关闭文件 
myFile.Close();