I think the problem is likely that you aren't reading in individual words. You're reading in lines. std::istream::get, when used with a c-string, behaves a lot like std::getline, except that it will not remove the newline from the stream. Using the extraction operator (std::cin >> word) might make things easier for you, if not as safe.