国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
WINCE 文本讀寫操作總結 .

1.C語言函數(shù)fopen(),式例代碼:

 

  1. //author:firehood   
  2. //data:  2011-5-19  
  3.  
  4. #include <stdio.h>  
  5. #include <tchar.h>   
  6.   
  7. int _tmain(int argc, _TCHAR* argv[])  
  8. {  
  9.     // 創(chuàng)建或打開二進制文件,并以追加方式打開   
  10.     FILE *pFile=_tfopen(_T("http://NAND2//FileLog1.txt"), _T("wab+"));  
  11.     if(pFile)  
  12.     {  
  13.         fwprintf(pFile, _T("%s/n"), _T("test1"));  
  14.         fwprintf(pFile, _T("%s/n"), _T("test2"));  
  15.         fwprintf(pFile, _T("%s/n"), _T("test3"));  
  16.         fclose(pFile);  
  17.     }  
  18.   
  19.     // 讀文件   
  20.     pFile=_tfopen(_T("http://NAND2//FileLog1.txt"), _T("rb"));  
  21.     TCHAR str[20];  
  22.     if(pFile)  
  23.     {  
  24.         while(_ftscanf(pFile,_T("%s/n"),str)!=EOF)  
  25.         {  
  26.             _tprintf(_T("%s/n"),str);  
  27.         }  
  28.         fclose(pFile);  
  29.     }  
  30.     return 0;  
  31. }  

2.C++ fstream,式例代碼:

  1. //author:firehood   
  2. //data:  2011-5-19   
  3.   
  4. #include <tchar.h>   
  5. #include <fstream>   
  6. #include <string>   
  7. #include <iostream>   
  8. using namespace std;  
  9.   
  10. int _tmain(int argc, _TCHAR* argv[])  
  11. {  
  12.     fstream file;  
  13.     // 以追加方式打開文件,只寫操作   
  14.     file.open("http://NAND2//FileLog.txt", ios_base::out | ios_base::app);  
  15.     if(file.is_open())  
  16.     {  
  17.         file << "test1" << endl;  
  18.         file << "test2" << endl;  
  19.         file << "test3" << endl;  
  20.         file.flush();  
  21.         file.close();  
  22.     }     
  23.   
  24.     // 以只讀方式打開文件   
  25.     file.open("http://NAND2//FileLog.txt", ios_base::in);  
  26.     if(!file.is_open())  
  27.     {  
  28.         cout << "Open file failed"<<endl;  
  29.         exit (1);  
  30.     }  
  31.     string str;  
  32.     while (!file.eof())  
  33.     {   
  34.         // 獲取一行數(shù)據(jù)   
  35.         getline(file,str);  
  36.         cout << str.c_str() << endl;  
  37.     }  
  38.     file.close();  
  39.     return 0;  
  40. }  

3.mfc CFile、CStdioFile類

  1. //author:firehood   
  2. //data:  2011-5-19   
  3.   
  4. #include <tchar.h>   
  5. #include <afx.h>   
  6.   
  7. int _tmain(int argc, _TCHAR* argv[])  
  8. {  
  9.     CStdioFile cFile;  
  10.     // 寫文件   
  11.     if(!cFile.Open(_T("http://NAND2//FileLog2.txt"),CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))  
  12.     {  
  13.         printf("Create file failed../n");  
  14.         return false;  
  15.     }  
  16.   
  17.     cFile.WriteString(L"test1");  
  18.     cFile.WriteString(L"test2");  
  19.     cFile.WriteString(L"test3");  
  20.     cFile.Close();  
  21.   
  22.     // 讀文件   
  23.     if(!cFile.Open(_T("http://NAND2//FileLog2.txt"),CFile::modeRead | CFile::typeBinary))  
  24.     {  
  25.         printf("Open file failed../n");  
  26.         return false;  
  27.     }  
  28.     CString str;  
  29.     while(cFile.ReadString(str))  
  30.     {  
  31.         // 輸出   
  32.         _tprintf(_T("%s/n"),str);  
  33.     }  
  34.     cFile.Close();  
  35.     return 0;  
  36. }  

CFile 寫文件操作示例,支持ANSI、UNICODE中文輸出。

  1. //author:firehood   
  2. //data:  2011-5-19   
  3.   
  4. #include <tchar.h>   
  5. #include <afx.h>   
  6.   
  7. int _tmain(int argc, _TCHAR* argv[])  
  8. {  
  9.     CFile cFile;  
  10.     if(cFile.Open(_T("D://FileLog3.txt"),CFile::shareExclusive|CFile::modeCreate|CFile::modeWrite))  
  11.     {  
  12. #ifdef  _UNICODE   
  13.         ULONGLONG dwFileLen = cFile.GetLength();     
  14.         if (0 == dwFileLen) // 文件為空時寫入UNICODE字節(jié)序標記      
  15.         {     
  16.             const unsigned char LeadBytes[]  = {0xff, 0xfe};     
  17.             cFile.Write(LeadBytes, sizeof(LeadBytes));     
  18.         }  
  19. #endif   
  20.         TCHAR *str=_T("中文字符串");  
  21.         cFile.Write(str,_tcslen(str)*sizeof(TCHAR));  
  22.         cFile.Close();  
  23.     }  
  24.     else  
  25.     {  
  26.         printf("Create file failed/n");  
  27.     }  
  28.     return 0;  
  29. }  
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
使用 InternetReadFile 來獲取文件 | 學步園
轉(zhuǎn)載:MFC文件操作,很全面
C++ wave文件的寫入與讀取
孫鑫VC視頻教程筆記之第十二課“文件操作(含注冊表操作)”
文件操作
Windows編程中各種操作文件的方法
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服