Question #255459

Assignment: Functions


void printBanner() – This function should open the file “banner.txt” in the same directory as the program, and print it’s contents to the terminal. It does not depend on any other functions.


Expert's answer

#include<iostream>
#include<fstream>
using namespace std;


void printBanner(){

       ifstream myReadFile;
         myReadFile.open("banner.txt");
         cout<<"testing of the function call"<<endl;
         char output[100];
         if (myReadFile.is_open()) {
                cout<<"testing of banner print if fucntion"<<endl;
         while (!myReadFile.eof()) {


            myReadFile >> output;
            cout<<output;
            cout<<"Banner printed successfully"<<endl;


            }
        }
    myReadFile.close();
}
int main(){

cout<<"test"<<endl;
printBanner();

return 0;
}

Output:


LATEST TUTORIALS
APPROVED BY CLIENTS