| 94 | } |
| 95 | |
| 96 | void show_words(const Words& words) |
| 97 | { |
| 98 | const size_t field_width {max_word_length(words) + 1}; |
| 99 | const size_t words_per_line {8}; |
| 100 | std::cout << std::format("{:{}}", *words[0], field_width); // Output first word |
| 101 | |
| 102 | size_t words_in_line {}; // Number of words in current line |
| 103 | for (size_t i {1}; i < words.size(); ++i) |
| 104 | { // Output newline when initial letter changes or after 8 per line |
| 105 | if ((*words[i])[0] != (*words[i - 1])[0] || ++words_in_line == words_per_line) |
| 106 | { |
| 107 | words_in_line = 0; |
| 108 | std::cout << std::endl; |
| 109 | } |
| 110 | std::cout << std::format("{:{}}", *words[i], field_width); // Output a word |
| 111 | } |
| 112 | std::cout << std::endl; |
| 113 | } |