c++ 查找string子串是否存在

#include <iostream>
#include <string>
using namespace std;

int main()
{
	std::string _Str = "abcdefg";
	if (string _Tmpy= "def"; string::npos != _Str.find(_Tmpy))  // c++17 if、switch语句初始化
	{
		cout << "找到该字符串:" << _Tmpy << endl;
	}
	else
	{
		cout << "该字符串不在_Str中" << endl;
	}
	return 0;
}

版权声明:本文为weijianjain原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。