github

Made bySaurav Hathi

MCQ Test C/C++: File Operations

Q1:

Which operator is used to insert the data into file in C++?

Tags:
Section:
Core Programming
Options:
Q2:

In C++, which function is used to set the position of the next character to be extracted from the input stream?

Tags:
Section:
Core Programming
Options:
Q3:

What is the output of this C++ program?

#include <iostream>

#include <fstream>

using namespace std;

int main ()

{

int length;

char * buffer;

ifstream is;

is.open ("sample.txt", ios :: binary );

is.seekg (0, ios :: end);

length = is.tellg();

is.seekg (0, ios :: beg);

buffer = new char [length];

is.read (buffer, length);

is.close();

cout.write (buffer, length);

delete[ ] buffer;

return 0;

}

Tags:
Section:
Core Programming
Options:
Q4:

What is the output of this C++ program?

#include<iostream>

#include <fstream>

using namespace std;

int main ()

{

ofstream outfile ("test.txt");

for (int n = 0; n < 100; n++)

{

outfile << n;

outfile.flush();

}

cout << "Done";

outfile.close();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q5:

By seeing which operator does this C++ program stop getting the input?

#include <iostream>

#include <fstream>

using namespace std;

int main ()

{

char ch;

streambuf * p;

ofstream os ("test.txt");

auto pbuf = os.rdbuf();

do {

ch = cin.get();

p -> sputc(ch);

} while (ch != '.');

os.close();

return 0;

}

Tags:
Section:
Core Programming
Options:
Q6:

Which member function is used to determine whether the stream object is currently associated with a file in C++?

Tags:
Section:
Core Programming
Options:
Q7:

Which header file is used for reading from and writing to a file in C++?

Tags:
Section:
Core Programming
Options:
Q8:

In C++, for binary files, a ______ must be appended to the mode string.

Tags:
Section:
Core Programming
Options:
Q9:

In C++, in case of error fopen() will return?

Tags:
Section:
Core Programming
Options:
Q10:

In C++, FILE is of type?

Tags:
Section:
Core Programming
Options:
Q11:

What is the meant by ‘a’ in the following operation in C++?

fp = fopen(“Random.txt”, “a”);

Tags:
Section:
Core Programming
Options:
Q12:

In C, fputs function writes a string to a file that only ends with a newline?

Tags:
Section:
Core Programming
Options:
Q13:

What is the output of this C code?

#include <stdio.h>

#include <string.h>

int main()

{

char line[3];

FILE *fp;

fp = fopen("newfile.txt", "r");

while (fgets(line, 3, fp))

fputs(line, stdout);

return 0;

}

Tags:
Section:
Core Programming
Options: