You are writing a program. Give the necessary statements to open a file and to confirm that the file has been successfully opened for writing. Important: Why bother to test?
What will be an ideal response?
```
include
#include
#include
int main()
{
using std::ifstream;
using std::cout;
ifstream inStream;
inStream.open("myFile.txt");
if (inStream.fail())
{
cout << "Input file failed to open\n";
exit(1);
}
}
```
If you try to open an input file that does not exist (This is easy to do.) the call to open will fail. If the file permissions are set so that we cannot read (for input files) or write (for output files) then the open will also fail. The program should crash if the open command, but two of my compilers generate executables that continue to run, doing unexpected things.
You might also like to view...
All macros are created in a programming language called:
A) Rich Text Format. B) Java Script. C) Hypertext Markup Language. D) Visual Basic for Applications.
The OSI model is divided into four layers
Indicate whether the statement is true or false.
The syntax to specify an image to display in place of a bullet is the text url followed by the path and filename of the image file, enclosed in ____.
A. quotes B. parentheses C. Both A and B. D. Neither A nor B.
Some networks combine signals to connect smaller networks and form one larger network.?
Answer the following statement true (T) or false (F)