-
What is the output of this program?
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int len;
char * buff;
ifstream is;
is.open ("Example.txt", ios :: binary );
is.seekg (0, ios :: end);
len = is.tellg();
is.seekg (0, ios :: beg);
buff = new char [len];
is.read (buff, len);
is.close();
cout.write (buff, len);
delete[] buff;
return 0;
}
-
- Example.text
- This is example
- Example
- Compilation Error
- Runtime Error
Correct Option: E
In this program, if the file exist, it will read the file. Otherwise it will throw an exception. A runtime error will occur because the value of the length variable will be “-1” if file doesn’t exist and in line 13 we are trying to allocate an array of size “-1”.