有两个文件A,B。我想要一个文件C,C中含有的是B文件中剔除与A相同行的数据。
用C++编写,用到fstream,ifstream,set以及vector。
#include <fstream> #include <iostream> #include <vector> #include <set> using namespace std; struct strless : public std::binary_function<const char*, const char*, bool> { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int _tmain(int argc, _TCHAR* argv[]) { ifstream comparefile; comparefile.open("E:\\a\\tasks.txt",ios::in); set<char*,strless> sline; char (*lines)[100] = new char[200][100]; int count = 0; while(!comparefile.eof()) { comparefile.getline(lines[count],100); sline.insert(lines[count]); ++count; } comparefile.close(); ifstream sourcefile; sourcefile.open("E:\\a\\ttt.txt",ios::in); char (*lines1)[100] = new char[1000][100]; count = 0; vector<char*> vline; while(!sourcefile.eof()) { sourcefile.getline(lines1[count],100); if(!sline.count(lines1[count])) vline.push_back(lines1[count]); ++count; } sourcefile.close(); fstream targetfile; targetfile.open("E:\\a\\list.txt",ios::app); vector<char*>::iterator vitr = vline.begin(); while(vitr!= vline.end()) { targetfile<<*vitr<<endl; ++vitr; } targetfile.close(); return 0; }
时间: 2024-10-06 02:48:51