模板类的使用

advance的使用:

	list<int> list_num;
	for (int i=0;i< 10; i++)
	{
		list_num.push_back(i);
	}
	list<int>::iterator ops;
	ops = list_num.begin();
	cout<<*ops<<endl;

	advance(ops, 3);
	cout<<*ops<<endl;

	advance(ops, -1);
	cout<<*ops<<endl;

打印结果

0

3

2


distance的使用

	list<int>::iterator nPos = find(list_num.begin(), list_num.end(), 5);
	if (nPos != list_num.end())
	{
		cout<<"the distance:"<<distance(list_num.begin(), nPos)<<endl;
	}
找到的5到开始的距离是5



iter_swap的使用

	iter_swap(nPos, list_num.begin());
	for (list<int>::iterator pos=list_num.begin(); pos != list_num.end(); ++pos)
	{
		cout<<*pos<<"  ";
	}
交换了第5的位置和第一个位置的置

string忽略大小写的比较与忽略大小写的子串查找

cout<<"**********************"<<endl;

	string str_one = "THANKYOU";
	string str_two = "ThankYou";
	if (str_one.size() == str_two.size() &&
		equal(str_one.begin(), str_one.end(), 
		str_two.begin(),
		nocase_compare))
	{
		cout<<"equal"<<endl;
	}
	else
	{
		cout<<"not equal"<<endl;
	}

	//查找子串
	str_two = "yOu";
	string::iterator pos;
	pos = search(str_one.begin(), str_one.end(),
				str_two.begin(),str_two.end(),
				nocase_compare);
	if (pos == str_one.end())
	{
		cout<<"not find"<<endl;
	}
	else
	{
		cout<<"find"<<" at index:"<<pos-str_one.begin()<<endl;
	}
	return ;
}

BOOL nocase_compare(char c1, char c2)
{
	return toupper(c1)==toupper(c2);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值