标  题: 在哪儿创建临文件                                 
发信人: Pacific (无情~~~Nolove), 信区: VisualC
发信站: BBS 水木清华站 (Fri Oct 16 17:30:41 1998)


                                                                                 
    调用SDK函数GetTempPath可以确定临时文件的目录,该函数首先为临时路径            
检测TMP环境变量:如果没有指定TMP,检测TMP环境变量,然后返回到当前目录。          
下例说明了如何创建一个临时文件。                                                 
…                                                                               
     //get unique temporary file.                                                
     CString strFile;                                                            
     GetUniqueTempName (strFile);                                                
     TRY                                                                         
     {                                                                           
        //Create file and write data.Note that file is closed                    
        //in the destructor of the CFile object.                                 
        CFile file (strFile,CFile:: modeCreate | CFile:: modeWrite);             
                                                                                 
        //write data                                                             
     }                                                                           
                                                                                 
     CATCH (CFileException, e)                                                   
     {                                                                           
        //error opening file                                                     
     }                                                                           
     END_CATCH                                                                   
…                                                                               
                                                                                 
Void GetuniqueTempName (CString& strTempName)                                    
{                                                                                
     //Get the temporary files directory.                                        
     TCHAR szTempPath  [MAX_PATH];                                               
     DWORD dwResult=:: GetTempPath (MAX_PATH, szTempPath);                       
     ASSERT (dwResult);                                                          
                                                                                 
     //Create a unique temporary file.                                           
     TCHAR szTempFile  [MAX_PATH];                                               
     UINT nResult=GetTempFileName (szTempPath, _T ("~ex"),0,szTempfile);         
     ASSERT (nResult);                                                           
                                                                                 
     strTempName=szTempFile;                                                     
}                                                                                
                                                                                 

--
        老鸟有交待,中鸟要等待,菜鸟要忍耐。
        老鸟级功夫:吹牛、聊天、玩MUD 、发呆。
        中鸟级功夫:睡觉、灌水、玩游戏、NT&VC。
        菜鸟级功夫:学习、泡妞、玩篮球、And so on

        My E-Mail: Nolove@263.net

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: yazhou.bbs@bbs.net.t]
※ 修改:.fzx 于 Aug  9 16:44:05 修改本文.[FROM: heart.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.536毫秒