简单错误记录

完成一个简单错误记录模块
1、循环记录,记录不超过8条,对于相同错误记录(文件名,行号匹配),则错误计数加1
2、文件名超过16字符的,只取最后16个字符
3、文件可能包括路径,只保留文件名
</pre><pre code_snippet_id="363096" snippet_file_name="blog_20140525_1_1687667" name="code" class="cpp">#include <iostream>  
#include <string>  
using namespace std;  
  
struct Recond  
{  
    string filename;  
    string linenum;  
    int num;  
};  
  
int main()  
{  
    bool flag = true;  
    int i = 0;  
    int j = 0;  
    string temp = "";  
    string s = "";  
    Recond recond[8] = {{"","",1},{"","",1},{"","",1},{"","",1},{"","",1},{"","",1},{"","",1},{"","",1}}; //存储所有文件名和行号  
    string filename = "";     //记录文件名  
    string linenum = "";      //记录行号  
    int recond_idx = 0;  
    int count = 0;  
    size_t pathidx = 0;  
  
    while (cin>>filename>>linenum)  
    {  
        flag = true;  
         s = "";  
         pathidx = filename.find_last_of('\\',filename.size()-1); //返回最后一个“\”的索引  
              
        if(pathidx == string::npos)   //不存在路径  
        {  
            if(filename.size() > 16)  //文件名超过16字符  
            {  
                s.assign(filename,filename.size() - 16,16);  
                filename = s;  
            }  
              
  
            for(j = 0; j < 8; ++j)   //查找是否相同记录  
            {  
                if(filename == recond[j].filename && linenum == recond[j].linenum)  
                {  
                    ++(recond[j].num);  
                    flag = false;  
                    break;  
                }  
            }  
  
            if(flag)   //新增加记录  
            {  
                recond[recond_idx].filename = filename;  
                recond[recond_idx].linenum = linenum;  
                recond[recond_idx].num = 1;  
                recond_idx++;  
            }  
        }  
        else    //存在路径  
        {  
            s.assign(filename,pathidx+1,filename.size() - pathidx - 1);  //获取文件名  
            //cout<<filename<<linenum<<endl;  
            filename = s;  
  
            if(filename.size() > 16)  //文件名超过16字符  
            {  
                s = "";  
                s.assign(filename,filename.size() - 16,16);  
                filename = s;  
            }  
  
            for(j = 0; j < 8; ++j)   //查找是否相同记录  
            {  
                if(filename == recond[j].filename && linenum == recond[j].linenum)  
                {  
                    ++(recond[j].num);  
                    flag = false;  
                    break;  
                }  
            }  
  
            if(flag)   //新增加记录  
            {  
                recond[recond_idx].filename = filename;  
                recond[recond_idx].linenum = linenum;  
                recond[recond_idx].num = 1;  
                recond_idx++;  
            }  
        }  
  
        if(recond_idx == 8)   //循环记录  
        {  
            recond_idx = 0;  
        }  
    }  
  
  
  
    for(i = 0; i < 8; ++i)  
    {     
        if(recond[i].filename == "")  
        {  
            continue;  
        }  
  
        cout<<recond[i].filename<<" "<<recond[i].linenum<<" "<<recond[i].num<<endl;  
    }  
  
    return 0;  
}  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值