Problem

Each of the following programs or program segments has errors. Find as many as you can....

Each of the following programs or program segments has errors. Find as many as you can.

A) fstream file(ios::in | ios::out);

file.open("info.dat");

if (!file)

{

cout << "Could not open file.\n";

}

B) ofstream file;

file.open("info.dat", ios::in);

if (file)

{

cout << "Could not open file.\n";

}

C) fstream file("info.dat");

if (!file)

{

cout << "Could not open file.\n";

}

D) fstream dataFile("info.dat", ios:in | ios:binary);

int x = 5;

dataFile << x;

E) fstream dataFile("info.dat", ios:in);

int x;

while (dataFile.eof())

{

dataFile >> x;

cout << x << endl;

}

F) fstream dataFile("info.dat", ios:in);

char line[81];

dataFile.get(line);

G) fstream dataFile("info.dat", ios:in);

char stuff[81];

dataFile.get(stuff);

H) fstream dataFile("info.dat", ios:in);

char stuff[81] = "abcdefghijklmnopqrstuvwxyz";

dataFile.put(stuff);

I) fstream dataFile("info.dat", ios:out);

struct Date

{

int month;

int day;

int year;

};

Date dt = { 4, 2, 98 };

dataFile.write(&dt, sizeof(int));

J) fstream inFile("info.dat", ios:in);

int x;

inFile.seekp(5);

inFile >> x;

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT