zoukankan      html  css  js  c++  java
  • 遍历文件下所有文件

     1 _finddata_t file;
     2 
     3     char* szFilePack="F:\RTMFP\measurement data\ME4\recursive2\lossbyte\*.txt";
     4     long lf;
     5     if ((lf=_findfirst(szFilePack,&file))==-1)//==优先级较高所以要加括号,找到文件夹下面第一个符合的文件
     6     {
     7         cout<<"cannot find file"<<endl;
     8     }
     9     else
    10     {
    11         cout<<"1111 "<<file.name<<endl;
    12         ifstream infile("F:\RTMFP\measurement data\ME4\recursive2\lossbyte\"+string(file.name));
    13         if (infile==0)
    14             cout<<"infile open failed! "<<file.name<<endl;
    15         else
    16         {
    17             //cout<<"1111 "<<file.name<<endl;
    18             int lossb=0;
    19             string line,word;
    20             istringstream linestream;
    21             while(getline(infile,line))
    22             {
    23                 linestream=istringstream(line);
    24                 linestream>>word;
    25                 linestream>>word;
    26                 linestream>>word;
    27                 lossb+=atoi(word.c_str());
    28             }
    29             lossbytes[file.name]=lossb;
    30         //    cout<<_findnext(lf,&file)<<endl;
    31         
    32             while(_findnext(lf,&file)==0)
    33             {
    34                 cout<<"1111 "<<file.name<<endl;
    35                 //cin>>x;
    36                 int lossb=0;
    37                 string line,word;
    38                 ifstream infile("F:\RTMFP\measurement data\ME4\recursive2\lossbyte\"+string(file.name));
    39                 istringstream linestream;
    40                 while(getline(infile,line))
    41                 {
    42                     linestream=istringstream(line);
    43                     linestream>>word;
    44                     linestream>>word;
    45                     linestream>>word;
    46                     lossb+=atoi(word.c_str());
    47                 }
    48                 lossbytes[file.name]=lossb;
    49             }
    50         }
    51     }
  • 相关阅读:
    python-面向对象-类
    python- collections-time-datetime
    python-json-pickle-shelve-random-os-sys-hashlib
    python-递归函数
    python-迭代器
    python-内置函数
    python-易错问题
    python-闭包函数和装饰器
    pytho-函数作用域
    List 拆分集合与 读写XML配置文件
  • 原文地址:https://www.cnblogs.com/xaf-dfg/p/3875728.html
Copyright © 2011-2022 走看看