偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

C++獲取文件具體方法詳解

開發(fā) 后端
C++編程語言對于文件的操作是一個(gè)比較基礎(chǔ)而且重要的操作。我們今天將會為大家詳細(xì)介紹其中C++獲取文件的像相關(guān)操作,方便大家理解。

在這篇文章中,我們將會為大家詳細(xì)介紹一下有關(guān)C++獲取文件的相關(guān)方法。對于剛剛接觸C++編程語言不久的朋友們來說,這篇文章介紹的內(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++獲取文件的寫法:

  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寫法標(biāo)準(zhǔn)格式簡介
  2. C++統(tǒng)計(jì)對象個(gè)數(shù)方法詳解
  3. C++ #define預(yù)處理指令特點(diǎn)評比
  4. C++二維數(shù)組初始化相關(guān)應(yīng)用技巧分享
  5. C++模擬event關(guān)鍵字具體實(shí)現(xiàn)方案
責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2009-11-23 19:16:32

路由器測試

2009-12-03 18:23:23

2010-02-04 11:23:25

C++反射機(jī)制

2009-11-23 15:10:28

PHP獲取當(dāng)前url

2010-07-21 14:33:01

刪除telnet

2010-02-01 17:02:53

C++產(chǎn)生隨機(jī)數(shù)

2010-02-03 13:26:53

C++計(jì)時(shí)

2009-12-31 15:05:00

Silverlight

2009-12-16 15:04:26

Ruby實(shí)現(xiàn)strea

2009-12-31 14:12:40

Silverlight

2009-12-03 14:43:46

phpMyAdmin配

2011-04-01 13:34:12

zabbix

2010-02-03 09:59:42

C++文件流操作

2010-02-01 14:53:42

C++屬性

2010-02-02 18:01:47

C++字符串替換函數(shù)

2009-12-25 16:52:57

網(wǎng)絡(luò)接入控制

2010-04-23 13:53:29

Oracle密碼

2009-12-18 16:56:05

ADO.NET應(yīng)用程序

2010-02-02 13:57:31

C++解析#pragm

2009-12-01 10:11:51

PHP自動獲取關(guān)鍵詞
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號