From: http://school.cnd8.com/vc/jiaocheng/33274.htm

参考上面网址中的文章,写了下面的例子,环境:windows XP SP3 +  VC6

#include <cstdlib >
#include <stdlib.h >
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;

int main(int argc, char * argv[])
{
	regex expression("(\\d+)-(\\d+)-(\\d+)"); // 注意转义方式
	string in("Today: 2007-06-23");
	cmatch what;
	// 如果用 regex_match 方法将需要完全匹配,
	// 不能在字符串中找寻模式,可用于验证输入
	if (regex_search(in.c_str(), what, expression))
	{
		for(int i = 0 ; i < what.size(); i++)
		{
			cout<<"str: "<<what[i].str()<<endl;
		}
	}
	return 0;
} 
程序运行结果:
str: 2007-06-23
str: 2007
str: 06
str: 23
Press any key to continue

 

注意:

本文所使用的boost库版本为:boost_1_34_0。请大家一定要看清楚了,一些高版本的boost库已经不再支持vc6了,而是支持更高版本的Visual Studio IDE(7.1以上)。

另外,编译之前,需要将libboost_regex-vc6-sgd-1_34.lib拷贝到程序根目录下,该文件是在“nmake -f vc6.mak”时产生的。

相关文章:

  • 2022-12-23
  • 2021-11-15
  • 2021-07-11
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案