C++ find函数简单应用

find函数可在已知字符串中查找子串

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string s1 = "Rey Dennis Steckler";
	string s2 = "Dennis";
	string s3 = "Ed Wood";

	int f;
	f = s1.find(s2);

	if(f < s1.length())
		cout<<"Found at index: "<<f<<endl;
	else
		cout<<"not found"<<endl;

	f = s1.find(s3);
	if(f < s1.length())
		cout<<"Found at index: "<<endl;
	else
		cout<<"not found"<<endl;

	string s4 = "bby";
	string s5 = "bx";

	cout<<s4.find_first_of(s5)<<endl;
	cout<<s4.find_first_not_of(s5)<<endl;

	return 0;
	
}


C++ find函数简单应用

上一篇:C/C++ unit testing tools (39 found)---reference


下一篇:六种主流编程语言(C、C++、Python、JavaScript、PHP、Java)特性对比