How to print the contents of a text file in c++

  c++, file, txt

Hello i am trying to read and print the contents of my text file which just says hello but it doesn’t print anything out.

int main() {
    string input;
    char filename[50];
    ifstream infile;
    cin.getline(filename, 50);
    infile.open("HI.txt");// txt file

    if (!infile.is_open()) {
        exit(EXIT_FAILURE);
    }
    char word[50];
    infile >> word;
    while (infile.good()) {
        cout << word << " ";
        infile >> word;
   }

Source: Windows Questions C++

LEAVE A COMMENT