Each of the following programs or program segments has errors. Find as many as you can.65. fstream file(ios::in | ios::out);file.open("info.dat");if (!file){cout << "Could not open file.\n";}66. ofstream file;file.open("info.dat", ios::in);if (file){cout << "Could not open file.\n";}67. fstream file("info.dat");if (!file){cout << "Could not open file.\n";}68. fstream dataFile("info.dat", ios:in | ios:binary);int x = 5;dataFile << x;69. fstream dataFile("info.dat", ios:in);char stuff[81];dataFile.get(stuff);70. fstream dataFile("info.dat", ios:in);char stuff[81] = "abcdefghijklmnopqrstuvwxyz";dataFile.put(stuff);71. fstream dataFile("info.dat", ios:out);struct Date{int month;int day;int year;};Date dt = { 4, 2, 98 };dataFile.write(&dt, sizeof(int));72. fstream inFile("info.dat", ios:in);int x;inFile.seekp(5);inFile >> x;
Each of the following programs or program segments has errors. Find as many as you can.
65. fstream file(ios::in | ios::out);
file.open("info.dat");
if (!file)
{
cout << "Could not open file.\n";
}
66. ofstream file;
file.open("info.dat", ios::in);
if (file)
{
cout << "Could not open file.\n";
}
67. fstream file("info.dat");
if (!file)
{
cout << "Could not open file.\n";
}
68. fstream dataFile("info.dat", ios:in | ios:binary);
int x = 5;
dataFile << x;
69. fstream dataFile("info.dat", ios:in);
char stuff[81];
dataFile.get(stuff);
70. fstream dataFile("info.dat", ios:in);
char stuff[81] = "abcdefghijklmnopqrstuvwxyz";
dataFile.put(stuff);
71. fstream dataFile("info.dat", ios:out);
struct Date
{
int month;
int day;
int year;
};
Date dt = { 4, 2, 98 };
dataFile.write(&dt, sizeof(int));
72. fstream inFile("info.dat", ios:in);
int x;
inFile.seekp(5);
inFile >> x;
Trending now
This is a popular solution!
Step by step
Solved in 2 steps