cpp: count-word/ optimized to linear time

Checks if the word matches while reading the file.