HTML Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int main (){
    char filename[50];
    ifstream asd;
    cin.getline(filename,50);
    asd.open(filename);
    
    //to close the program if txt does not open
    if (!asd.is_open()){
                        exit(EXIT_FAILURE);
                        }
                        
    char asdasd [50];
    asd >> asdasd;
    while(asd.good()){
                      cout << asdasd << " " << " ";
                      asd >> asdasd;
                      }
                      
    system ("pause");
    return 0;
}
I learned this from a tutorial and i mostly understood it but i'm having some problems to understand why it needs <while(asd.good()){> before cout and another <asd >> asdasd;> after cout. Without the while i only have the first word of the txt and without the second <asd >> asdasd> i have compile error. Any clarification d be really appreciated. Thanks