1、已有文本文件:
string dataList;使用fopen讀?。?p>FILE *fpListFile = fopen(dataList.c_str(), "r");if (!fpListFile){ cout << "0.can't open " << dataList << endl; return -1;}2、按行讀取數據:方法一:char loadImgPath[1000];while(EOF != fscanf(fpListFile, "%s", loadImgPath)){ ...}其中,loadImgPath不能使用string類型,即使用loadImgPath.c_str()接收數據也不行,否則讀取內容為空;方法二:
char buff[1000];while(fgets(buff, 1000 ,fpListFile) != NULL){ char *pstr = strtok(buff, "/n"); ... }其中,buff接收的數據包括了換行符,所以在使用之前需先將刪除換行符;
新聞熱點
疑難解答
圖片精選