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.

11.4

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) infile.open(argc);
  • (g) sfinout.open(file,ios::in |ios::out| ios::ate);
Answer
  • (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:
    infile.open (argv[1]) :
  • (f) The argument file must write as ” file” because this is string type.
    Correction :
    fstream sfinout;
    sfinout.open (“file”, ios::inios::out, ios::ate);

Next Previous