把代码改成方法调用。
时间:2011-11-26
来源:互联网
把下面的代码改成 方法 调用这个方法时 让参数1 和参数2 可以正确传值就行,谢谢。我做的方法 不能正确传值 。 方法的参数要用什么类型呢。谢谢,帮我写个例子。VS2010的。感谢,感谢。
char *szStr = "a.comb.comc.com";//参数1
boost::cmatch mat;
boost::regex reg(".*com");//参数2
bool r=boost::regex_match( szStr, mat, reg);
if(r) //如果匹配成功
{
//显示所有子串
for(boost::cmatch::iterator itr=mat.begin(); itr!=mat.end(); ++itr)
{
// 指向子串对应首位置 指向子串对应尾位置 子串内容
cout << itr->first-szStr << ' ' << itr->second-szStr << ' ' << *itr << endl;
}
}
char *szStr = "a.comb.comc.com";//参数1
boost::cmatch mat;
boost::regex reg(".*com");//参数2
bool r=boost::regex_match( szStr, mat, reg);
if(r) //如果匹配成功
{
//显示所有子串
for(boost::cmatch::iterator itr=mat.begin(); itr!=mat.end(); ++itr)
{
// 指向子串对应首位置 指向子串对应尾位置 子串内容
cout << itr->first-szStr << ' ' << itr->second-szStr << ' ' << *itr << endl;
}
}
作者: xieaqiang 发布时间: 2011-11-26
void MyFunction(char *pszStr, char *pszReg)
{
//char *szStr = "a.comb.comc.com";//参数1
boost::cmatch mat;
//boost::regex reg(".*com");//参数2
boost::regex reg(pszReg);//参数2
//bool r=boost::regex_match( szStr, mat, reg);
bool r=boost::regex_match( pszStr, mat, reg);
if(r) //如果匹配成功
{
//显示所有子串
for(boost::cmatch::iterator itr=mat.begin(); itr!=mat.end(); ++itr)
{
// 指向子串对应首位置 指向子串对应尾位置 子串内容
cout << itr->first-szStr << ' ' << itr->second-szStr << ' ' << *itr << endl;
}
}
}
{
//char *szStr = "a.comb.comc.com";//参数1
boost::cmatch mat;
//boost::regex reg(".*com");//参数2
boost::regex reg(pszReg);//参数2
//bool r=boost::regex_match( szStr, mat, reg);
bool r=boost::regex_match( pszStr, mat, reg);
if(r) //如果匹配成功
{
//显示所有子串
for(boost::cmatch::iterator itr=mat.begin(); itr!=mat.end(); ++itr)
{
// 指向子串对应首位置 指向子串对应尾位置 子串内容
cout << itr->first-szStr << ' ' << itr->second-szStr << ' ' << *itr << endl;
}
}
}
作者: Saleayas 发布时间: 2011-11-26
就是封装成一个函数么
字符串参数用指针传递
字符串参数用指针传递
作者: xianglitian 发布时间: 2011-11-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28