C Write a Boolean valuereturning function definition called
C++
Write a Boolean value-returning function definition called OpenFile with 2 parameters. The first parameter, a string, contains the name of the file that is entered for opening. The name of the file entered must be made available to the caller of this function. The second parameter, an ifstream, represents the input stream to use The function prompts the user for the name of the file to open and opens the file The function returns a value of true if the file was successfully open and a value of false if the file was not successfully opened.Solution
#include <iostream>
 #include <fstream>
using namespace std;
 bool openFile(ifstream& a, string fin)
 {
     a.open(fin.c_str());
     if(a.is_open()) {
         return true;
     }
     else {
         return false;
     }
 }
 int main()
 {
    ifstream a;
    bool result;
    string fileName;
    cout<<\"Enter file name to check status :\";
    cin >> fileName;
    result = openFile(a,fileName);
    if(result) {
        cout<<\"File successfully opened\"<<endl;
    }
    else {
        cout<<\"File open status Failed\"<<endl;
    }
 }

