查找文件关键字的程序(VC++6.0)

【求助】求一个查找文件关键字的程序(VC++6.0)
哪位大哥帮忙写一个   查找文本文件内   有无某关键字的程序啊   用Visual   C++   6.0版本。
          用Unicode码读写   并匹配。
          这是毕业设计的一部分内容,还没做出来,都快毕不了业了!着急啊!


------解决方案--------------------
根据给定的字典,查找目标文件是否存在匹配,并完成替换

#include <map>
#include <fstream>
#include <string>
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
string line;
int index;

//这里根据字典文件创建 map
map <string, string> strmap;
string prestring, sufstring;
ifstream filedic( "test1.txt "); //字典文件
while(!filedic.eof())
{
getline(filedic, line);
index = line.find( "=== ");
prestring=line.substr(0, index);
sufstring=line.substr(index+3);
strmap.insert(make_pair(prestring, sufstring));
//cout < <prestring < < " ~ " < <sufstring < <endl;
}

int flag=0;
string value;
map <string, string> ::iterator iter;
ifstream infile( "test.txt "); //输入文件
ofstream outfile( "out.txt "); //输出文件
while(!infile.eof())
{
getline(infile, line);
//cout < <line < <endl;
if(line == " </OBJECT> ")
{flag=0; outfile < <line < <endl;} //注意这个内容的输出不要漏了
if(flag)
{
index = line.find( "value ")+7;
value=line.substr(index); //截取 value= " 后面的string
value=value.substr(0, value.length()-2); //去除后面 ">
iter = strmap.find(value);
if(iter != strmap.end()) //如果找到了,进行翻译写入
outfile < <line.substr(0, index) < <strmap[value] < < "\ "> " < <endl;
else
outfile < <line < <endl; //否则输出原文
}
if(line == " <LI> <OBJECT type=\ "text/sitemap\ "> ")
{flag=1; outfile < <line < <endl;} //注意这个内容的输出不要漏了
}

system( "pause ");
return 0;
}


测试文件内容:
test.txt:
<LI> <OBJECT type= "text/sitemap ">
<param name= "Name " value= "Welcome ">
<param name= "Local " value= "Welcome\welcome.htm ">
<param name= "ImageNumber " value= "1 ">
</OBJECT>

test1.txt:
over===结束
Welcome ===欢迎
get started===开始

输出文件 out.txt:
<LI> <OBJECT type= "text/sitemap ">
<param name= "Name " value= "欢迎> "
<param name= "Local " value= "Welcome\welcome.htm ">
<param name= "ImageNumber " value= "1 ">
</OBJECT>
------解决方案--------------------
C++写的啊!看不出来?不要太在意测试文件的内容。
------解决方案--------------------
那就不是为了你的需求写的程序。自己体会着看看,你的需求无非就是打开文件,读出所有的内容,在内容里面用字符串函数(比如strstr)或者自己写个内存查找函数来找关键字就行了。

大致代码如下,copy自上面各门的代码

C/C++ code

string key = "关键字";
bool   bFind = false;
ifstream   infile( "test.txt ");   //输入文件 
while(!infile.eof()) 
{ 
    getline(infile,   line); 
    if (line.find(key)>=0)
    {                                
        bFind = true;
        cout << "找到了" <<endl;     //否则输出原文 
         break;
     } 
} 
if (!bFind) cout<<"没找到"<<endl;