华为OJ:开发一个简单错误记录功能小模块,能够记录出错的代码所在的文件名称和行号。

用到了类string的length(), size(),find_first_of(),find_last_of(),substr(),push_back()函数 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

struct errorLog
{
	string name;
	string line;
	int count;
};
errorLog createErrorLog(string name, string line)
{
	errorLog log;
	int nameSize = name.length();
	int index = -1;
	index = name.find_last_of('\\');
	name = name.substr(index + 1);
	log.name = name;
	log.line = line;
	log.count = 1;
	return log;
}

void recordErrorLog(int number, errorLog log, vector<errorLog> & resu)
{
	bool isRepeat = false;
	for (int i = 0; i < resu.size(); i++)
	{
		if (resu[i].name == log.name && resu[i].line == log.line)
		{
			resu[i].count++;
			isRepeat = true;
			break;
		}
	}
	if (isRepeat == false)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值