How to check if a substring exists in a string with C++

1 Answer

0 votes
#include <iostream>

int main()
{
	std::string s = "c++ c c# java", search = "java";

	if (s.find(search) != std::string::npos)
		std::cout << "Exists" << "\n";
	else
		std::cout << "Not exists" << "\n";
}



/*
run:

Exists

*/

 



answered Mar 27, 2017 by avibootz
edited Apr 15, 2024 by avibootz

Related questions

1 answer 175 views
1 answer 204 views
1 answer 199 views
1 answer 126 views
...