c++ vector的几个常见操作的用法测试


// 测试两种vector参数的区别
test_vector_func(std::vector<std::string> v1, std::vector<std::string>& v2)
{
	CCLOG("[1] 0x%x 0x%x", &v1, &v2);

	v1.clear();
	v2.clear();
}

std::vector<std::string> v1 = {"1", "2", "3"};
std::vector<std::string> v2 = { "1", "2", "3" };
CCLOG("[0] 0x%x 0x%x", &v1, &v2);
test_vector_func(v1, v2);


// 测试两个vector之间的批量复制
// 把v2全部复制到v1当中
std::vector<std::string> v1;
std::vector<std::string> v2 = { "1", "2", "3" };
v1.insert(v1.begin(),  v2.begin(),  v2.end());



// 遍历删除vector
// 如果v1中包含v2中的点,则将v1中的该点删除
void removePos(std::vector<Data>& v1, Vector<Data>& v2)
{
	for (auto it = v1.begin(); it != v1.end(); )
	{
		Point pos = (*it)->pos;

		bool isFind = false;
		for (auto it2 = v2.begin(); it2 != v2.end(); ++it2)
		{
			Point pos2 = *it2->pos;
			if (pos == pos2)
			{
				isFind = true;
				break;
			}
		}
		if (isFind)
		{
			it = v1.erase(it);
		}
		else
			++it;
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值