首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于c++统计文本关键字的输入有关问题 用于mfc

2013-09-06 
关于c++统计文本关键字的输入问题用于mfc要求编写一个统计关键字的c++,要可以输入关键字并比较。之前找到过

关于c++统计文本关键字的输入问题 用于mfc
要求编写一个统计关键字的c++,要可以输入关键字并比较。之前找到过一个c++的程序如下:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int Match(const char *key, const char *data, int len)
{
for (int i=1; i<len; i++)
{
if (*(key + i) != *(data+i))
{
return 0;
}
}
return 1;
}

void main() 
{
ifstream fin("1.txt"); 
    const int LINE_LENGTH = 100; 
    char str[LINE_LENGTH];  
    while( fin.getline(str,LINE_LENGTH) )
    {    
char *pchKeyword = "do";
char *pchData = str;
char *pchCurPos = pchData;
int iKeyLen = strlen(pchKeyword);
int iDataLen = strlen(pchData);
int iMatchNum = 0;
for (int i=0; i<iDataLen-iKeyLen; i++)
{
if (*pchKeyword == *pchCurPos)
{
if (Match(pchKeyword, pchCurPos, iKeyLen))
{
iMatchNum++;
}
}
pchCurPos++;
}
printf("Match number:%d\n",iMatchNum);
}
}


这样就可以统计文本中的do的出现次数,但是现在要求输入关键词,不可以直接使用那段代码,但是不知道怎么改.并且这段代码要用于mfc中请问
CString s1;
GetDlgItem(IDC_EDIT2)->GetWindowTextW(s1);
得到的CSstring型要怎么转换,谢谢 c++ mfc
[解决办法]
要转码吧
把CString中的UNICODE字符串转换成ANSI字符串,再去读文件统计。
[解决办法]
s1 = 输入 就是了呗

热点排行