find()函数及其他常用函数总结

一:find()函数:

第一种,algorithm头文件的find()。
    使用方法:find(begin,end,value),一般用 容器.end()来判断查找成功与否。
    参数1 是容器或者数组的起始地址(容器.begin()或者数组名),也可以是任意地址,不非法即可;

    参数2是结束查找的地址(容器.end()或者数组名+长度),value是想要查找的字符或者字符串

    查找成功将返回迭代器(容器)或者指针(数组),否则返回end()

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std; 
int main()
{
	vector<int> v;
	for(int i=0;i<5;i++){
		v.push_back(i);
	}
	if(find(v.begin(),v.end(),4)!=v.end()){  
		printf("找到的下标为%d\n",find(v.begin(),v.end(),4)-v.begin()); //获取元素的下标 
	}else{
		printf("该元素不存在\n");
	}
	return 0;
}

第二种,string自带的find(),可查找指定字符串和指定字符。
使用方法:如在string1中查找string2,string1.find(string2);返回值为string2第一次在string1中出现的位置。
若希望在特定位置开始查找,可使用 string1.find(string2,location);
如果找不到,则返回值为string::npos ,即对于string,通过a.find(val)==string::npos来做判断是否查找成功

#include<iostream>
#include<string>
using namespace std; 
int main()
{
	string s1,s2;
	s1 = "hello world";
	s2 = "world";
	if(s1.find(s2)!=string::npos){   //查找字符串 
		printf("s2在s1中的起始下标为%d\n",s1.find(s2)); 
	}else{
		printf("s1中不存在s2字符串"); 
	} 
	char c = 'e';
	if(s1.find(c)!=string::npos){   //查找字符 
		printf("字符c在s1中的起始下标为%d\n",s1.find(c)); 
	}else{
		printf("s1中不存在字符c"); 
	} 
	return 0;
}

二:max()、min()函数

#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cout<<"输入数据:";
	cin>>a>>b; 
	cout<<"最大者是"<<max(a,b)<<endl; //获取两数中的最大者
	cout<<"最小者是"<<min(a,b)<<endl; //获取两数中的最小者
	return 0;
}

三:atoi()函数,把字符串转换成整型数

头文件: #include <stdlib.h>

对于字符数组

#include<iostream>
#include<algorithm>
using namespace std; 
int main()
{
	char str[10] = "12345";
 	int n = atoi(str);
	printf("n = %d\n",n);
	return 0;
}

对于string类型的字符串,需要调用c_str()函数转换为字符数组后才能作为参数转换

#include<iostream>
#include<algorithm>
#include<string>
using namespace std; 
int main()
{
	string s = "12345";
	int n = atoi(s.c_str());
	printf("n = %d\n",n);
	return 0;
}

 

 

  • 73
    点赞
  • 546
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
https://assetstore.unity.com/packages/tools/find-reference-2-59092 FR2 helps instantly clean up asset references for your projects Email | Documentation | Forum Why FR2? - Optimize your projects reference to minimize build size - Split your big projects to smaller / managable modules - Safely remove all duplicated assets - Safely replace prefabs / materials / shader with another one - Remove obsolete assets that you don't need anymore How can FR2 help? Just select one or more asset in Project panel and FR2 will show you: - Exactly what's being included in each scene or in each prefab. Remember that one redundant reference may resulted in asset being duplicated in each assetbundles and increase AssetBundle build sizes (Animation / Texture / Audio duplication) or degrade performance (Material duplication - increase drawcalls) - Which assets referenced to and make selected assets included in the build. This will help you confident that intermediate project assets will not be included in final build - Duplicated assets you may accidentally copy over and over. Using FR2 you can then redidrect all those references to a single copy of your choice and safely delete other duplications (usage count of those assets should now be 0) - See all assets not being referenced by any other asset so you can delete them all without worrying about breaking any references. - GUID Tools Advanced tool where you can see GUID of each asset and redirect references from one asset to another You can use this to redirect all references to TextureA (using TextureA) to TextureB, the same applied for shader, materials, mesh... Beware that replace references is very powerful yet dangerous operation you'd better don't use it if you don't understand how GUID works in Unity Other Features - Full C# source code - Top notch support 24/7 - Blazing fast - built for HUGE PROJECTS - Support with Unity 4.3+ and Unity 5.x - Quickly disable FR2 when not in used (zeroing performance cost) - Display usage count in project panel so you know which asset being used and how many times it's being used - Find script dependencies (experimental, C# only) - Export assets with references

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值