65,211
社区成员
发帖
与我相关
我的任务
分享
//想完成关键字的替换
//请帮我看看如何完善红颜色的内容。谢谢了.....
void CFindFileDlg::ReplaceKeyWord()
{
CString strKeyWord;
m_KeyWordEdit.GetWindowText(strKeyWord);
string strKey = strKeyWord.GetBuffer(0); //得到关键字
CString strReplaceWord;
m_ReplaceWordEdit.GetWindowText(strReplaceWord);
string strReplace = strReplaceWord.GetBuffer(0); //得到替换字
ifstream in;
string line = "";
setlocale(LC_ALL,"Chinese-simplified"); //VS2003中使用ifstream的时候不需要,仅仅是VS2005中
for (int j = 0; j < (int)m_KeyWord_FileList.size(); j++) //m_KeyWord_FileList是存放所有含指定关键字的文件完整路径
{
in.open(m_KeyWord_FileList[j].c_str(), fstream::in);
if(!in)
{
return;
}
while(getline(in, line))
{
if(strstr(line.c_str(), strKey.c_str()))
{
//这里应该怎么写,才能真正实现替换???????
}
else
{
string strInfo;
char strTemp[MAX_PATH] = {0};
sprintf(strTemp, "找不到:", strKey.c_str());
strInfo = strTemp;
::MessageBox(NULL, strInfo.c_str(), "提示", MB_ICONINFORMATION);
}
}
}
in.clear();
in.close();
}