MFC中,#define STR "d\TLD<4,$.."CFile ReportFile;
CFileException e;
LPCTSTR pFileName = _T("File.txt");
ReportFile.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) ReportFile.Write();想请高手指教一下,红色部分如何写,才能将宏STR所对应的字符串中的每个字符转换成为数字输出到文件中???我试了好多方法,好像atoi也不管用,结果输出成了:
100 92 ?4 ?6 ?8 ?0 ?2 ?4 ?6 ?8 ? 也不知道?和乱码到底怎么能消除,请各位高手指教!!并祝周末愉快!

解决方案 »

  1.   

    CString strTemp;
    strTmep.Format("%d", atoi(STR ));
    ReportFile.Write(strTemp, strTemp.GetLength()); 
    没试 不知行不行
      

  2.   

    Writes data from a buffer to the file associated with the CFile object.
    virtual void Write(
       const void* lpBuf,
       UINT nCount 
    );
     
    write 的作用是把一个缓冲区的数据写入到 文件里面
    你可以这样  把"d\TLD <4,$.."里面的 字符先换成 对应的数字具体就是 把数据串里面的字符一个一个读取出来,然后转换成 数字 (ASCII) 再写入到 文件里面就是一个循环能搞定的事情
      

  3.   

    完整的代码
    你上面的只有一个 ‘\’是不正确的 需要'\\' 这个是转意的CString str="d\\TLD <4,$..";CFile ReportFile; 
    CFileException e; 
    LPCTSTR pFileName = _T("File.txt"); 
    ReportFile.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) ;for(int i=0;i<str.GetLength();++i)
    {
    char t=str.GetAt(i);
    CString temp;
    temp.Format("%d",t);
    ReportFile.Write(temp,temp.GetLength()); 
    }
    ReportFile.Close();
      

  4.   

    "d\TLD <4,$.." 
    代表的是11个符号,我是想获取每个符号所对应的asc值,
    如d代表的是100;我想在文件中存储的是100,这个怎么实现呢??