File Streams and String Streams CPP MCQ

Errorlogger
0
1. Which operator is used to insert the data into file?
a) >>
b) <<
c) <
d) None of the mentioned



2. Which function is used to position back from the end of file object?
a) seekg
b) seekp
c) Both a & b
d) None of the mentioned



3. How many number of objects are used for input and output to a string?
a) 1
b) 2
c) 3
d) 4



4. What is the output of this program?
  1.     #include <iostream>
  2.     #include <fstream>
  3.     using namespace std;
  4.     int main () 
  5.     {
  6.         int length;
  7.         char * buffer;
  8.         ifstream is;
  9.         is.open ("sample.txt", ios :: binary );
  10.         is.seekg (0, ios :: end);
  11.         length = is.tellg();
  12.         is.seekg (0, ios :: beg);
  13.         buffer = new char [length];
  14.         is.read (buffer, length);
  15.         is.close();
  16.         cout.write (buffer, length);
  17.         delete[] buffer;
  18.         return 0;
  19.     }
a) This is sample
b) sample
c) Error
d) Runtime error



5. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         char first, second;
  6.         cout << "Enter a word: ";
  7.         first = cin.get();
  8.         cin.sync();
  9.         second = cin.get();
  10.         cout << first << endl;
  11.         cout << second << endl;
  12.         return 0;
  13.     }
a) first
b) second
c) Returns first 2 letter or number from the entered word
d) None of the mentioned



6. What is the output of this program?
  1.     #include<iostream>
  2.     #include <fstream>
  3.     using namespace std;
  4.     int main () 
  5.     {
  6.         ofstream outfile ("test.txt");
  7.         for (int n = 0; n < 100; n++)
  8.         {
  9.             outfile << n;
  10.             outfile.flush();
  11.         }
  12.         cout << "Done";
  13.         outfile.close();
  14.         return 0;
  15.     }
a) Done
b) Error
c) Runtime error
d) None of the mentioned



7. What is the output of this program?
  1.     #include <iostream>
  2.     using namespace std;
  3.     int main ()
  4.     {
  5.         int a = 100;
  6.         double b = 3.14;
  7.         cout << a;
  8.         cout << endl;
  9.         cout << b << endl << a * b;
  10.         endl (cout);
  11.         return 0;
  12.     }
a) 100
b) 3.14
c) 314
d) All of the mentioned



8. By seeing which operator thus this program stops getting the input?
  1.     #include <iostream>
  2.     #include <fstream>
  3.     using namespace std;
  4.     int main ()
  5.     {
  6.         char ch;
  7.         streambuf * p;
  8.         ofstream os ("test.txt");
  9.         pbuf = os.rdbuf();
  10.         do {
  11.             ch = cin.get();
  12.             p -> sputc(ch);
  13.         } while (ch != '.');
  14.         os.close();
  15.         return 0;
  16.     }
a) dot operator
b) insertion operator
c) $ symbol
d) None of the mentioned



9. Which member function is used to determine whether the stream object is currently associated with a file?
a) is_open
b) buf
c) string
d) None of the mentioned



10. Which header file is used for reading and writing to a file?
a) #include<iostream>
b) #include<fstream>
c) #include<file>
d) None of the mentioned

Tags

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(30)

Our website uses cookies to enhance your experience. Check Now
Accept !