代碼如下:
void ListPath(string path, list& files)
{
//文件句柄
long hFile = 0;
int count=0;
//文件信息
struct _finddata_t fileinfo;
string p;
if((hFile = _findfirst(p.assign(path).append("\*").c_str(),&fileinfo)) != -1)
{
do
{
count++;//這一行注釋掉沒事
cout<<count<<endl;//這一行注釋掉程序崩了
if((fileinfo.attrib & _A_SUBDIR))
{
if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
{
ListPath( p.assign(path).append("\").append(fileinfo.name), files );
}
}
else
{
int len=strlen(fileinfo.name);
if(fileinfo.name[len-1]=='t'&&fileinfo.name[len-2]=='x'&&fileinfo.name[len-3]=='t'&&fileinfo.name[len-4]=='.')
{
ifstream filein(StringToChar(p.assign(path).append("\").append(fileinfo.name)));
stringstream buffer;
buffer<<filein.rdbuf();
string source(buffer.str());
if(KMP(source))
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
}
}
}
}
while(_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}
這是你的代碼嗎?上面的沒對齊,如果是嗎,那麼具體崩潰的時候有沒有報什麼錯誤?
void ListPath(string path, list& files)
{
//文件句柄
long hFile = 0;
int count=0;
//文件信息
struct _finddata_t fileinfo;
string p;
if((hFile = _findfirst(p.assign(path).append("\*").c_str(),&fileinfo)) != -1)
{
do
{
count++;//這一行注釋掉沒事
cout<<count<<endl;//這一行注釋掉程序崩了
if((fileinfo.attrib & _A_SUBDIR))
{
if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
{
ListPath( p.assign(path).append("\").append(fileinfo.name), files );
}
}
else
{
int len=strlen(fileinfo.name);
if(fileinfo.name[len-1]=='t'&&fileinfo.name[len-2]=='x'&&fileinfo.name[len-3]=='t'&&fileinfo.name[len-4]=='.')
{
ifstream filein(StringToChar(p.assign(path).append("\").append(fileinfo.name)));
stringstream buffer;
buffer<<filein.rdbuf();
string source(buffer.str());
if(KMP(source))
{
files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
}
}
}
}while(_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
}