C++从文件中查找特定的字符串,并提取该字符串

mac2022-06-30  57

记录一个小技巧,使用C++从文件中查找特定标记的字符串,并提取该字符串。

用到了CString的方法,十分的简单,用于数据分析很方便。

这是我截取的压缩编码试验程序中的代码,通过这段代码可以提取X264输出的SSIM值

FILE *fp_statfile=fopen("x264_output.txt","rb"); CString filecontent(""); //文件内容读入内存 while(!feof(fp_statfile)){ filecontent.AppendChar(getc(fp_statfile)); } //查找X264的SSIM数值 //X264特征字符串 CString featurestr("SSIM Mean Y:"); //查找,返回字符串位置 int paraloc=filecontent.Find(featurestr); CString parastr; //找到了的话 if(paraloc!=-1){ //跳过特征字符串,提取5位 parastr=filecontent.Mid(paraloc+featurestr.GetLength(),5); TRACE("%s\n",parastr); } fclose(fp_statfile);

转载于:https://www.cnblogs.com/leixiaohua1020/p/3902181.html

相关资源:MFC 查找文件中指定字符串
最新回复(0)