C++ Primer(第五版) 17.3.4节练习

这篇博客主要探讨了C++ Primer第五版中的17.3.4节,包括了17.24、17.25、17.26和17.27四个练习题目。通过详细解析,深入理解C++中模板特化、模板元编程等关键概念。
摘要由CSDN通过智能技术生成

17.24    

#include <iostream>
#include <regex>

using namespace std;

int main()
{
	string phone = 
		"(\\()?(\\d{3})(\\))?([-. ])?(\\d{3})([-. ])?(\\d{4})";
	regex r(phone);
	smatch m;
	string s;
	string fmt = "$2.$5.$7";
	
	while (getline(cin, s))
		cout << regex_replace(s, r, fmt) << endl;
		
	return 0;
}

17.25    

#include <iostream>
#include <regex>
#include <vector>

using namespace std;

int main()
{
	string phone = 
		"(\\()?(\\d{3})(\\))?([-. ])?(\\d{3})([-. ])?(\\d{4})";
	regex r(phone);
	string s;
	string fmt = "$2.$5.$7";
	
	while (getline(cin, s)) {	
		s = regex_replace(s, r, fmt);
		sregex_iterator it(s.begin(), s.end(), r);
		cout << it->str() << endl;
	}
		
	return 0;
}

17.26

#inclu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值