c++正则表达式

中国MOOC网 青岛大学《数据结构与算法》 周强

正则表达式返回的true或者false

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <regex> 
using namespace std;
int main(){
	string str = "hello4";
	regex r("[a-z]+"); //是不是全是字母 
	cout<< regex_match(str, r) << endl;
	return 0;
} 

将vector中类型设置为对象

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <fstream> 
using namespace std;
class Stu{
	private:
		string id;
		int score;
	public:
		Stu(string id, int score){
			this->id = id;
			this->score = score;
		}
		friend ostream& operator << (ostream& o, const Stu& s){ //插入流的重载 
			o<<"("<<s.id<<","<<s.score<<")";
			return o;
		}
};
int main(){
	vector<Stu> v;
	v.emplace_back("zhangsan",100); //原地构造 
	v.emplace_back("lisi",94);
	for(auto x: v)
		cout<<x<<endl;
	return 0;
}

模板的使用

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
template<class T> //模板 
class Table{
	public:
		T a;
		T b;
	print(){
		cout<<a<<" "<<b;
	}
};
int main(){
	Table<int> t; //创建对象
	t.a= 2;
	t.b = 3;
	t.print();  
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值