Write a program that prompts for an input file name, receives the input file name in a C-string. The program should check for errors opening a file. It is not necessary for the program to do anything other than open the file.

What will be an ideal response?


```
#include
#include //unnecessary, fstream gets this
#include //for exit(int)
int main()
{
using std::ifstream;
using std::cout;
using std::cin;

char name[16];
cout << "enter a file name, 15 characters max:\n";
cin << name;
ifstream inStream;
inStream.open(name);
if (inStream.fail())
{
cout << "Opening file " << name <<" failed\n";
exit(1);
}
// code that uses the file
```

Computer Science & Information Technology

You might also like to view...

When you swap variables, you need to use a(n) ____________________ variable.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

In the Package for CD dialog box, to change the play order for multiple presentations:

A) select the Renumber Files option. B) click the Sort by option. C) select a file and click the up or down arrow to reposition files. D) select the Reorder Files check box.

Computer Science & Information Technology

What is a field or block of text used to determine the position of objects in a document?

A) Template B) Placeholder C) Text box D) Drawing canvas

Computer Science & Information Technology

The Retinex theory states that colors are not determined in isolation.

a. true b. false

Computer Science & Information Technology