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:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS