Advertisement
Guest User

c++17

a guest
Sep 26th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <optional>
  4.  
  5.  
  6. int numberOfOccurences(wchar_t character, std::optional<std::wstring> string) {
  7.   if(!string) return 0;
  8.   int i = 0;
  9.   for(auto c : *string) {
  10.     if(c == character) i++;
  11.   }
  12.   return i;
  13. }
  14.  
  15. int main() {
  16.   std::cout << numberOfOccurences(L'🤔', {L"is this bait 🤔🤔🤔?"}) << std::endl;
  17.   std::cout << numberOfOccurences(L'🤡', std::nullopt) << std::endl;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement