Language: C++

#include<cstdio>
#include<vector>
using namespace std;

int main(){
  char str[1200];
  int pos = 0;
  vector<string> ans;

  fgets(str,1200,stdin);

  while(1){
    string word;
    while(str[pos] != '.' && str[pos] != ' ' && str[pos] != ',' && str[pos] != '\n')word.push_back(str[pos++]);
    
    if(str[pos] == '\n')break;
    
    if( 2<(int)word.size() && (int)word.size()<7)ans.push_back(word);
    pos++;
  }
    
  for(int i=0;i<(int)ans.size()-1;i++){
    cout << ans[i] << " ";
  }
  if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:10: error: 'string' was not declared in this scope
    8 |   vector<string> ans;
      |          ^~~~~~
a.cc:3:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    2 | #include<vector>
  +++ |+#include <string>
    3 | using namespace std;
a.cc:8:16: error: template argument 1 is invalid
    8 |   vector<string> ans;
      |                ^
a.cc:8:16: error: template argument 2 is invalid
a.cc:13:11: error: expected ';' before 'word'
   13 |     string word;
      |           ^~~~~
      |           ;
a.cc:14:85: error: 'word' was not declared in this scope
   14 |     while(str[pos] != '.' && str[pos] != ' ' && str[pos] != ',' && str[pos] != '\n')word.push_back(str[pos++]);
      |                                                                                     ^~~~
a.cc:18:16: error: 'word' was not declared in this scope
   18 |     if( 2<(int)word.size() && (int)word.size()<7)ans.push_back(word);
      |                ^~~~
a.cc:18:54: error: request for member 'push_back' in 'ans', which is of non-class type 'int'
   18 |     if( 2<(int)word.size() && (int)word.size()<7)ans.push_back(word);
      |                                                      ^~~~~~~~~
a.cc:22:26: error: request for member 'size' in 'ans', which is of non-class type 'int'
   22 |   for(int i=0;i<(int)ans.size()-1;i++){
      |                          ^~~~
a.cc:23:5: error: 'cout' was not declared in this scope
   23 |     cout << ans[i] << " ";
      |     ^~~~
a.cc:3:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<vector>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:23:16: error: invalid types 'int[int]' for array subscript
   23 |     cout << ans[i] << " ";
      |                ^
a.cc:25:15: error: request for member 'size' in 'ans', which is of non-class type 'int'
   25 |   if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
      |               ^~~~
a.cc:25:22: error: 'cout' was not declared in this scope
   25 |   if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
      |                      ^~~~
a.cc:25:22: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:25:43: error: request for member 'size' in 'ans', which is of non-class type 'int'
   25 |   if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
      |                                           ^~~~
a.cc:25:56: error: 'endl' was not declared in this scope
   25 |   if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
      |                                                        ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<vector>
  +++ |+#include <ostream>
    3 | using namespace std;