#include <iostream>
#include <string>


void print_nth_word(std::istream& in, std::size_t nth){
    std::string word;
    std::size_t n{};

    while(in >> word){
        if(++n % nth == 0)
            std::cout << word << '\n';
    }
}


void print_nth_word(const std::string& s, std::size_t nth){
    std::string word;
    std::size_t n{};

   for(auto it = s.begin(); it < s.end(); ++it){
        while(it < s.end() && *it == ' ')
            ++it;

        if(it == s.end())
            return;

        word.clear();

        while(it < s.end() && *it != ' ')
            word.push_back(*it++);

        if(++n % nth == 0)
            std::cout << word << '\n';
    }
}

#include <sstream>

int main(){
    std::string text = "Tell the truth, Nobody will do Anything.";
    std::stringstream stream{text};

    print_nth_word(text, 3);
    print_nth_word(stream, 3);
}
