Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <optional>
- int numberOfOccurences(wchar_t character, std::optional<std::wstring> string) {
- if(!string) return 0;
- int i = 0;
- for(auto c : *string) {
- if(c == character) i++;
- }
- return i;
- }
- int main() {
- std::cout << numberOfOccurences(L'🤔', {L"is this bait 🤔🤔🤔?"}) << std::endl;
- std::cout << numberOfOccurences(L'🤡', std::nullopt) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement