Question: Identify and correct the errors in the code segments in Exercises a) through f) a) fstream myfile(info.dat); if(myfile) { cout < < Error in file

Identify and correct the errors in the code segments in Exercises a) through f)

a)

fstream myfile("info.dat");

if(myfile)

{

cout << "Error in file opening.";

exit(1);

}

b)

ifstream fstr;

fstr.open("A:\info.dat", ios::out);

c)

ofstream fout("comparts.dat");

if(fout.fail())

{

cerr<<"Error in file opening.";

exit(1);

}

fout.seekp(-2*sizeof(compart), ios::end);

fout.read((char*)&part.sizeof(compart));

d)

ifstream fin("info.dat", ios::app);

fin<

fin.close();

e)

ofstream fstr("info.dat");

fstr>>x>>y;

fstr.close();

f)

fout.seekg(n*sizeof(int),ios::cur);

fout<

2. State the output produced by the following program

#include

#include

using namespace std;

int main()

{

char *course="OOP USING C++", ch;

ofstream ftest1("test.dat");

ftest1<

ftest1.close();

ifstream ftest2("test.dat");

ftest2.seekg(-8, ios::end);

ch=ftest2.get(); //reads a character

cout<

ftest2.seekg(2, ios::cur);

ch=ftest2.get(); //reads a character

cout<

return 0;

}

3. True or char c1, c2, c3, c4;

1. We use the infile function to read input from the keyboard.

2. We use the infile function to read input from a file.

3. You must create a link between an external disk file and an

ifstream object before you can read your input data

4. It is good practice to close an input file when you need no

further access to the file.

5. It is not possible to make input errors with the

sophisticated C++ I/O system.

4. True or false, assuming

1. Space (ASCII value 32) can be treated as a char.

2. We must put space between characters when we type them in at

the keyboard.

3. If we have cin>>c1>>c2>>c3>>c4; and type in only three

characters, our program will crash.

4. All computers recognize ASCII code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!