Language: C++

#include <iostream>
#include <string>
#include <list>
#include <cstring>

#define USE_SET

int main(void) {
  int K;

  std::string str;

  std::string s_;
  std::cin >> s_;
  const char* s = s_.c_str();

  std::cin >> str;
  K = std::stoi(str);

  size_t lsize = 0;
  size_t len = s_.length();

#if !defined(USE_SET)
  typedef struct s_set {
    int pos;
    int len;

    s_set(int i, int j) : pos(i), len(j) {
    }
  } set;
#endif

#if !defined(USE_SET)
  std::list<set> wlist;
  wlist.push_back(set(0, 1));
#else
  std::list<std::string> wlist;
  wlist.push_back(s_.substr(0, 1));
#endif

  for (int a = 'a'; a <= 'z' && lsize < K; ++a) {        /* a to z   */
    for (int b = 'a'; b <= 'z' && lsize < K; ++b) {      /* a to z   */
      for (int i = 0; i < len; ++i) {                    /* 0 to len */
        if (s[i] == a && (i+1 >= len || s[i+1] == b)) {
          for (int j = 1; j <= len - i && j <= K; ++j) {           /* length 1 to len - i */
            for (auto itr = wlist.begin(); itr != wlist.end(); ++itr) {
#if defined(USE_SET)
              int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
#else
              int cmp = s_.compare(i, j, *itr);
#endif
              if (cmp == 0) {
                break;
              }
              if (cmp < 0) {
#if defined(USE_SET)
                wlist.insert(itr, set(i, j));
#else
                wlist.insert(itr, s_.substr(i, j));
#endif
                lsize++;
                break;
              }
#if defined(USE_SET)
              if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
                wlist.push_back(set(i, j));
#else
              if (cmp > 0 && itr->c_str() == wlist.rbegin()->c_str()) {
                wlist.push_back(s_.substr(i, j));
#endif
                lsize++;
                break;
              }
            }
          }
        }
      }
    }
  }

  size_t idx = 0;
  for (auto &str : wlist) {
    idx++;
    //if (idx == K) {
      //std::cout << str << std::endl;
      //std::cout << str.pos << "," << str.len << std::endl;
      std::cout << s_.substr(str.pos, str.len) << std::endl;
    //}
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:51: error: 'class std::__cxx11::basic_string<char>' has no member named 'pos'; did you mean 'npos'?
   48 |               int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
      |                                                   ^~~
      |                                                   npos
a.cc:48:61: error: 'class std::__cxx11::basic_string<char>' has no member named 'len'
   48 |               int cmp = s_.compare(i, j, s_, itr->pos, itr->len);
      |                                                             ^~~
a.cc:57:35: error: 'set' was not declared in this scope
   57 |                 wlist.insert(itr, set(i, j));
      |                                   ^~~
a.cc:65:36: error: 'class std::__cxx11::basic_string<char>' has no member named 'pos'; did you mean 'npos'?
   65 |               if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
      |                                    ^~~
      |                                    npos
a.cc:65:59: error: 'class std::__cxx11::basic_string<char>' has no member named 'pos'; did you mean 'npos'?
   65 |               if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
      |                                                           ^~~
      |                                                           npos
a.cc:65:71: error: 'class std::__cxx11::basic_string<char>' has no member named 'len'
   65 |               if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
      |                                                                       ^~~
a.cc:65:94: error: 'class std::__cxx11::basic_string<char>' has no member named 'len'
   65 |               if (cmp > 0 && (itr->pos == wlist.rbegin()->pos && itr->len == wlist.rbegin()->len)) {
      |                                                                                              ^~~
a.cc:66:33: error: 'set' was not declared in this scope
   66 |                 wlist.push_back(set(i, j));
      |                                 ^~~
a.cc:87:34: error: 'class std::__cxx11::basic_string<char>' has no member named 'pos'; did you mean 'npos'?
   87 |       std::cout << s_.substr(str.pos, str.len) << std::endl;
      |                                  ^~~
      |                                  npos
a.cc:87:43: error: 'class std::__cxx11::basic_string<char>' has no member named 'len'
   87 |       std::cout << s_.substr(str.pos, str.len) << std::endl;
      |                                           ^~~