linux count number of times word appears in file

C++
grep -o 'word' filename | wc -l

Source

Also in C++: