65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <locale>
#include <boost/regex.hpp>
using namespace boost;
using namespace std;
wstring convert2wstr(string sToMatch)//将普通字符串转换为宽字符串
{
setlocale( LC_CTYPE, "zh_CN.gbk" );
int iWLen= mbstowcs( NULL, sToMatch.c_str(), sToMatch.length() );
wchar_t *lpwsz= new wchar_t[iWLen+1];
int i= mbstowcs( lpwsz, sToMatch.c_str(), sToMatch.length() );
wstring wsToMatch(lpwsz);
delete []lpwsz;
cout<<"i = "<<i<<endl;
return wsToMatch;
}
string wstr2str(wstring wsm)
{
int iLen= wcstombs( NULL, wsm.c_str(), 0 ); // 计算转换后字符串的长度。(不包含字符串结束符)
char *lpsz= new char[iLen+1];
int i= wcstombs( lpsz, wsm.c_str(), iLen ); // 转换。(没有结束符)
lpsz[iLen] = '\0';
string sToMatch(lpsz);
delete []lpsz;
return sToMatch;
}
int main()
{
string str="我:是 :中国人:民";
wstring ws=convert2wstr(str);
wregex expression(L"[\u4e00-\u9fa5]+");//提取所有汉字...
wsmatch what;
std::wstring::const_iterator start = ws.begin();
std::wstring::const_iterator end = ws.end();
while( boost::regex_search(start, end, what, expression) )
{
//这里面该写什么啊????
start = what[0].second;
}
return 1;
}