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.
#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:
Comments
Leave a comment