C++ File I/O, Console Output

Question: How can I get my console to properly display the contents of fileB?

I am trying to copy the contents of fileA.txt over to fileB.txt and display the contents of fileB.txt in the console. I have written code to do this, however the console only shows a blank box.

#include <iostream> // Read from files
#include <fstream>  // Read/Write to files
#include <string>
#include <iomanip>

void perror();

int main()
    using std::cout;
    using std::ios; 

    using std::ifstream;
    ifstream ifile; // ifile = input file
    ifile.open("fileA.txt", ios::in);

    using std::ofstream;
    ofstream ofile("fileB.txt", ios::out); // ios::app adds new content to the end of a file instead of overwriting existing data.; // ofile = output file

    using std::fstream;
    fstream file; // file open fore read/write operations.

    if (!ifile.is_open()) //Checks to see if file stream did not opwn successfully. 
        cout << "File not found."; //File not found. Print out a error message.
        ofile << ifile.rdbuf(); //This is where the magic happens. Writes content of ifile to ofile.

    using std::string; 
    string word; //Creating a string to display contents of files.

    // Open a file for read/write operations

    // Viewing content of file in console. This is mainly for testing purposes. 
    while (file >> word)
        cout << word << " ";

    return 0; //Nothing can be after return 0 in int main. Anything afterwards will not be run.



Question: How can I display the contents of fileB.txt in the console?

To display the contents of fileB.txt in the console, you can use the following code after opening the file:

ifstream bfile("fileB.txt");
string line;
while (getline(bfile, line)) {
    cout << line << endl;

This will read each line of fileB.txt and output it to the console. Make sure to close the file after you are finished: