C++ 获取 string 中某个字符首次出现的位置

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Simon798/article/details/102583293
// 没有找到返回 -1,找到返回字符对应的下标
int getStrSub(string str,char ch){

	int result = -1;

	for(int i=0;i<str.length();i++){
		if(str[i] == ch){
			result = i;
		}
	}

	return result;
}

猜你喜欢

转载自blog.csdn.net/Simon798/article/details/102583293