NOTE: We are sorry to say that Debugging Exercise question no 11.1 , 11.2 and 11.3 is unfortunately missed. We will come back with this question and answers very soon. Stay tune with us. Happy coding.


Find errors in the following statements.

  • (a) ifstream.infile(“DATA”);
  • (b) finl.getline(); //finl is input stream
  • (c) if(finl.eof() == 0) exit(1);
  • (d) close(f1);
  • (e);
  • (g),ios::in |ios::out| ios::ate);
  • (a) Error : Improper use of ifstream.

Correction : ifstream infile (“DATA”);

  • (b) Here you must give two argument for getline ( ) function one is string type variable name and another is string size. Such as
    char s[20];
    getline(s, 20);
  • (c) If we write
    if (fin1, eof ( ) = = 0)
    exit (1);
    it input only one character from file and then it will exit.
  • (d) close ( ) is void type argument function so it will be fl.close ( )
  • (e) argc is called argument counter and agrv is called argument vector so to open data file we can write the statement like this: (argv[1]) :
  • (f) The argument file must write as ” file” because this is string type.
    Correction :
    fstream sfinout; (“file”, ios::inios::out, ios::ate);

Next Previous