How to get all string from a vector that start with specific character in C++

1 Answer

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

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

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

	vector<string>::iterator it = vec.begin();

	while (it != vec.end()) {
		if (it[0][0] == 'c')
			cout << *it << endl;
		it++;
	}

	return 0;
}


/*
run:

c
c++

*/

 



answered Apr 29, 2018 by avibootz
...