Professional Documents
Culture Documents
2.Which function is used to position back from the end of file object?
a) seekg
b) seekp
c) both seekg & seekp
d) seekf
3.How many objects are used for input and output to a string?
a) 1
b) 2
c) 3
d) 4
#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;
}
a)This is sample
b) sample
c) Error
d) Runtime error
5.What will be the output of the following C++ code?
#include <iostream>
using namespace std;
int main ()
{
char first, second;
cout << "Enter a word: ";
first = cin.get();
cin.sync();
second = cin.get();
cout << first << endl;
cout << second << endl;
return 0;
}
a)first
b) second
c) returns first 2 letter or number from the entered word
d) third
#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;
}
a)Done
b) Error
c) Runtime error
d) DoneDoneDone
#include <iostream>
using namespace std;
int main ()
{
int a = 100;
double b = 3.14;
cout << a;
cout << endl;
cout << b << endl << a * b;
endl (cout);
return 0;
}
a)100
b) 3.14
c) 314
d) All of the mentioned
8.By seeing which operator thus this C++ program stops getting the input?
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
char ch;
streambuf * p;
ofstream os ("test.txt");
pbuf = os.rdbuf();
do {
ch = cin.get();
p -> sputc(ch);
} while (ch != '.');
os.close();
return 0;
}
a)dot operator
b) insertion operator
c) $ symbol
d) @ symbol
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) is_out
10.Which header file is used for reading and writing to a file?
a) #include<iostream>
b) #include<fstream>
c) #include<file>
d) #include<fe>
11 is a sequence of bytes.
Stream
Input stream
Output stream
None of above
12. The source stream that provides data to the program is called
Stream
Input stream
Output stream
None of above
13 The destination stream that receives output from the program is called
Stream
Input stream
Output stream
None of above
15 Which class is the base class for rest of the classes in stream classes?
ios
istream
streambuf
none of above
19 The class provides the facilities for formatted and unformatted output.
ostream
ostream_withassign
iostream_withassign
streambuf
24 The operator reads the data character by character and assigns it to the
indicated location.
>>
<<
c. << >>
d. None of above
25 Which of the following is not a part of ios formatted function?
width()
fill()
setf()
height()
ofstream
B. ifstream
C. fstream
D. iostream
28 It is not possible to combine two or more file opening mode in open () method.
TRUE
B. FALSE
C. May Be
D. Can't Say
A.Returns true if a file open for reading has reached the next character.
B. Returns true if a file open for reading has reached the next word.
C. Returns true if a file open for reading has reached the end.
D. Returns true if a file open for reading has reached the middle.
Which of the following true about FILE *fp
30 Which of the following methods can be used to open a file in file handling?
Using Open ( )
B. Constructor method
C. Destructor method
D. Both A and B
int main ()
int l;
char * b;
ifstream i;
l = i.tellg();
i.close();
delete[] b;
return 0;
A.Error
B. find
C. This is find
D. Runtime error
int main ()
fine = cin.get();
cin.sync();
course = cin.get();
return 0;
A.course
B. fine
C. Returns fine 2 letter or number from the entered word
D. None of the mentioned
If the file is opened for output operations and it already existed, no action is taken.
B. If the file is opened for output operations and it already existed, then a new copy is
created.
C. If the file is opened for output operations and it already existed, its previous content is
deleted and replaced by the new one.
D. None of the above