【文本数据找重复记录】2021-11-23
缘由在输入文件中找到所有相同的连续行组。在输出文件中放置每个这样的组的信息,包括重复行的文本,重复的数量和该组开始的行号。-编程语言-CSDN问答
void 文本数据找重复记录()
{//缘由https://ask.csdn.net/questions/7576185?spm=1010.2135.3001.5893&answer=53602933std::ifstream fi;fi.open("..\\Debug\\回复专用\\in.txt", std::ios::in);if (!fi.is_open())std::cout << "open file in.txt fail" << std::endl;std::ofstream fo;fo.open("..\\Debug\\回复专用\\out.txt", std::ios::out);if (!fo.is_open())std::cout << "open file out.txt fail" << std::endl;std::string str, str1, ju, sc; int line = 0, count = 1, zs = 0, w = 0;while (getline(fi, str1)){if (++line > zs && ju.find(std::to_string(zs) + ";") == -1){while (getline(fi, str))if (str == str1)++count, ju += std::to_string(line++) + ";";else ++line;++zs;if (count > 1)fo << str1 << " " << zs << " " << count << std::endl; else;fi.close(); fi.open("..\\Debug\\回复专用\\in.txt", std::ios::in);count = 1; line = 0; sc = std::to_string(zs - 1) + ";";if ((w = ju.find(sc)) != -1)ju = ju.replace(w, (sc).size(), ""); else;}}fo.close();
}
限制条件自己构建,不涉及原数据,这就是工巧之处,ju可用替换处理前面已过的多余的字符以节省字符串长度。