How to check if vector contains any string that starts with specific char in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::vector;
using std::string;

int main()
{
	vector<string> vec = { "c++", "c", "java", "python", "php" };

	bool result = std::any_of(vec.begin(), vec.end(), [](const string & s) {
		                      return s.size() > 0 && s[0] == 'j';
	});

	if (result)
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	return 0;
}


/*
run:

yes

*/

 



answered Feb 5, 2018 by avibootz
...