There are really many different possible solutions.
One idea is, to see a word as an element in a container, which is a string in this case. And with iterators, we can iterate over elements in a container.
One good iterator to iterate over elements in a string is the std::sregex_token_iterator. Here you can define a pattern for an element that you want to iterate over using a std::regex.
And with the help of std::distance, you can measure the number of elements in the range of 2 iterators.
All this glued together will give you a typical one liner:
#include <iostream>
#include <string>
#include <regex>
#include <algorithm>
#include <iterator>
const std::regex re{ R"(\w+)" };
const std::string text{ R"(Lorem ipsum dolor sit amet, consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero
eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
takimata sanctus est Lorem ipsum dolor sit amet.)" };
int main() {
// Output the number of words
std::cout << "\n\nNumber of words in text: "
<< std::distance(std::sregex_token_iterator(text.begin(), text.end(), re), {})
<< "\n\n";
return 0;
}