Hi Valentina, there is no need to explicitely handle file opening/closing. You could make the program accepting input from standard in and then redirect the intended file on program call. e.g.
my_program < my_input_file
Also, there is no need to explicitely find word boundaries,
cin
can gently do such a job for you.
Try
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector <string> vw;
while (true)
{
string word;
cin >> word;
if ( ! cin ) break;
vw.push_back(word);
}
cout << "count of words is " << vw.size();
}