怎样从文本1中找出乱码词,在文本2中找出对应语句,在文本3中输出来:
先建Win32控制台应用程序,再引入头文件:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> vstr;
fstream file1("d:\\test1.txt");
fstream file2("d:\\test2.txt");
fstream file3("d:\\test3.txt");
while(!file1.eof())
{
char buf[MAX_PATH];
file1.getline(buf,sizeof(buf));
string getStr = string((const char*)buf);
if(string::npos != getStr.find('?',0))
{
string str = getStr.substr(0,getStr.find('\t',0));
vstr.push_back(str);
}}
while(!file2.eof())
{
char buf[MAX_PATH];
file2.getline(buf1,sizeof(buf1));
string getStr1 = string((const char*)buf1);
for(int i=0; i < vstr.size();i++)
{
if(string::npos != getStr1.find(vstr[i],0))
{
file3<<getStr1<<endl;
break;
}
}}
file1.close();
file2.close();
file3.close();
return 0;
}