char szSplit[] = {"DesStr"};
string strDes;
FILE * fp = fopen("filename","a"); //打开文件
while(!(feof(fp))) //判断到结尾没有
{
char szbuf[1024 +1] = {0};
fgets(szbuf,1024,fp);//获取一行,或者1024个字符
string strBuf(szbuf);
size_t npos = strBuf.find(szDes);//查询特定字符位置
if(npos != std::string::npos)
{
strDes.assign(strBuf,npos-2,2);//获取前俩字符
}
}
fflush(fp);
fclose(fp);
这与你的txt文件中数据安排有关,没有普遍使用的方法。