#include#include #include int main() { std::vector myVec{1,1,2,3,3,3,4}; int numTwos = std::count(myVec.begin(), myVec.end(), 2); int numThrees = std::count(myVec.begin(), myVec.end(), 3); std::cout << "Number of twos: " << numTwos << std::endl; std::cout << "Number of threes: "<< numThrees << std::endl; return 0; }
#includeIn this example, we create a string `myString` with some characters. We use the `std::count` algorithm to count the number of occurrences of the characters 'l' and 'o' in the string. We then print out the results. Package/library: C++ standard library#include int main() { std::string myString = "hello world"; int numLs = std::count(myString.begin(), myString.end(), 'l'); int numOhs = std::count(myString.begin(), myString.end(), 'o'); std::cout << "Number of ls: " << numLs << std::endl; std::cout << "Number of ohs: "<< numOhs << std::endl; return 0; }