[C++] help with counting # of words in txt

hello everyone

i’m trying to count the number of words from an input stream (text file). i guess you can call it a word counter. Don’t worry about the outFile, I just want it to write the number to file so it can be saved when the console closes. :geek:

This is what I have so far.


#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;


int main() {
    
    ifstream inFile;
    ofstream outFile;

    inFile.open("C:/input.txt");
    outFile.open("C:/output.txt");
    
    char ch;
    int counter=0;
    while (!inFile.eof()) {
        
  



}
      counter++;
        }
    }
    
    
    outFile << counter;
    
    
    
    return 0;
}


The big empty space is where I’m stuck. I want to read every word individually and increment the counter. But if I use cstring (char aWord for example) it neglects the spaces in between the characters and outputs one long sentence, thus disregarding each individual word.

Input.txt can very well be any input file, say a chapter in a book, a couple paragraphs of lorem ipsum, anything.

Would this be possible using just arrays and loops?