日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
C++獲取文件具體方法詳解

在這篇文章中,我們將會(huì)為大家詳細(xì)介紹一下有關(guān)C++獲取文件的相關(guān)方法。對(duì)于剛剛接觸C++編程語(yǔ)言不久的朋友們來(lái)說(shuō),這篇文章介紹的內(nèi)容可以幫助他們解決一些在文件操作中經(jīng)常遇到的難題。

 
 
 
  1. /*read File*/  
  2. char *txt = NULL;  
  3. long txtlen;  
  4. //seek to file end to calculate file length  
  5. fseek(fp,0,SEEK_END);  
  6. txtlen=ftell(fp);  
  7. //rewind to file start  
  8. rewind(fp);  
  9. //read from file  
  10. txt = new char[txtlen + 1];  
  11. if (txt != NULL)   
  12. {  
  13. fread(txt,sizeof(char),txtlen,fp);  
  14. txt[txtlen]='\0';  
  15. fv.setData(txt);  
  16. }  
  17. //close file and destroy temp array  
  18. fclose(fp);  
  19. if(txt!=NULL)  
  20. {  
  21. delete []txt;  
  22. txt = NULL;  

C++獲取文件的寫(xiě)法:

 
 
 
  1. /*read File*/  
  2. ifstream in(filesrc);  
  3. if(in.fail())  
  4. {  
  5. printf("open file failed!\n");  
  6. }  
  7. else  
  8. {  
  9. string strtmp;  
  10. while (getline(in,strtmp))  
  11. {  
  12. fv.getData()+=strtmp;  
  13. fv.getData()+='\n';  
  14. }  
  15. in.close();  

以上就是我們?yōu)榇蠹医榻B的C++獲取文件相關(guān)方法。

【編輯推薦】

  1. C++ makefile寫(xiě)法標(biāo)準(zhǔn)格式簡(jiǎn)介
  2. C++統(tǒng)計(jì)對(duì)象個(gè)數(shù)方法詳解
  3. C++ #define預(yù)處理指令特點(diǎn)評(píng)比
  4. C++二維數(shù)組初始化相關(guān)應(yīng)用技巧分享
  5. C++模擬event關(guān)鍵字具體實(shí)現(xiàn)方案

文章名稱(chēng):C++獲取文件具體方法詳解
本文地址:http://www.5511xx.com/article/coghjss.html