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;
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.