ZKeeer 2017-01-03 12:18 采纳率: 100%
浏览 1059
已采纳

c++ 为什么不输出count,函数就崩了?

代码如下:

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);
    }
}

  • 写回答

1条回答 默认 最新

  • 小邓在路上 2017-01-04 01:26
    关注

    这是你的代码吗?上面的没对齐,如果是吗,那么具体崩溃的时候有没有报什么错误?

     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);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建