#include < fstream.h >
void main()
{
int num=0;
char c;
ifstream ifl;
ifl.open("CLASS.DAT",ios::in);
while(ifl)
{
ifl.get(c);
cout<< c;
num++;
cout<< num;
}
ifl.close();
cout<<"Total characters = "<< num;
#include < fstream.h >
struct Member
{
int code;
char name[20];
int age;
char sex;
};
void main()
{
Member m;
char c;
ofstream ofl;
ofl.open("MEMLIST.DAT", ios::app|ios::binary);
cout<<"nMember Code : ";
cin>>m.code;
c=cin.get();
cout<<"nMember Name : ";
cin.getline(m.name,20);
cout<<"nAge : ";
cin>>m.age;
c=cin.get();
cout<<"nMember Sex (M/F) : ";
cin>>m.sex;
ofl.write((char*)&m,sizeof(Member));
ofl.close();
File mode describes how the file is to be used. When we open a file using function open(), along with the filename we can also give the file mode. The general form of the function open() with two arguments is –
stream_object. open(“filename”, filemode);
The different file modes are –
ios :: in opens file for reading, i.e., in input mode
ios :: out opens file for writing, i.e., in output mode
ios :: app causes all output to that file to be appended to the end
ios :: ate seeks to end-of-file upon opening of the file. I/O operations can be anywhere within the file
ios :: trunk deletes the contents of the file
ios :: binary opens a file in binary mode. Default is text mode.
ios :: nocreate causes the open() function to fail if file does not already exist.
ios :: noreplace causes the open() function to fail if already exists.
There are 3 kinds of streams – input, output and input/output.
If we want to use the file for input i.e. reading, we must create an input stream, using class ifstream.
For example, ifstream ifl;
If we want to use the file for output i.e. writing, we must create an output stream, using class ofstream.
For example, ofstream ofl;
If we want to use the file for input as well as output, we must create a stream performing both input and output, using class fstream.
For example, fstream iofl;
#include < fstream.h >
class Employee
{
int empcode;
char empname[20];
char depart[20];
public:
void getdat()
{
cout<<"nEmployee Code : ";
cin>>empcode;
char c=cin.get();
cout<<"nEmployee Name : ";
cin.getline(empname,20);
cout<<"nDepartment : ";
cin.getline(depart,20);
}
void dispdat(){
cout<<"nEmployee Code : "<< empcode;
cout<<"nEmployee Name : "<< empname;
cout<<"nDepartment : "<< depart;
}
};
void main()
{
Employee e;
int num=0;
char fname[13];
cout<<"Enter file name ";
cin>>fname;
ofstream ofl;
ofl.open(fname, ios::app|ios::binary);
if(!ofl)
{
cout<<"Cannot open file "<< fname;
return;
}
cout<<"How many employees? ";
cin>>num;
for(int i=1;i<=num;i++)
{
e.getdat();
ofl.write((char*)&e,sizeof(Employee));
}
ofl.close();
#include < fstream.h >
#include < stdio.h >
class Book
{
int bookcode;
char bookname[20];
public:
void getdat()
{
cout<<"nBook Code : ";
cin>>bookcode;
char c=cin.get();
cout<<"nBook Name : ";
cin.getline(bookname,20);
}
void dispdat()
{
cout<<"nBook Code : "<< bookcode;
cout<<"nBook Name : "<< bookname;
}
int match(int cd)
{
if(cd==bookcode)
return 1;
else
return 0;
}
};
void main()
{
Book b;
int cd;
int found=0;
ofstream ofl;
ofl.open("temp.tmp", ios::out|ios::binary);
ifstream ifl;
ifl.open("Books.dat",ios::in|ios::binary);
cout<<"nEnter Book Code ";
cin>>cd;
while(ifl)
{
ifl.read((char *)&b,sizeof(Book));
found=b.match(cd);
if(found==0)
ofl.write((char *)&b,sizeof(Book));
}
ifl.close();
ofl.close();
remove("Books.Dat");
rename("temp.tmp", "Books.Dat");
#include < fstream.h >
#include < string.h >
struct Member
{ int code;
char name[20];
int age;
char sex;
};
void main()
{
Member m;
char c;
int cd;
ifstream ifl;
ifl.open("MEMLIST.DAT", ios::in|ios::binary);
cout<<"Enter code to find ";
cin>>cd;
c=cin.get();
while(ifl)
{
ifl.read((char *)&m,sizeof(Member));
if(cd==m.code)
{
cout<<"nMember Code : "<< m.code;
cout<<"nMember Name : "<< m.name;
cout<<"nAge : "<< m.age;
cout<<"nMember Sex : "<< m.sex;
break;
}
}
ifl.close();
The two file pointers are the get pointer and the put pointer. The get pointer is used with a file that is open for input and put pointer is used with a file open for output. A file is read from the position marked by the get pointer. In the same way, when a file is written, it is at the position marked by the put pointer.
These two pointers can be manipulated to move directly to a location in the file to read or write. The functions used for this are seekg() and seekp(). Two more functions may be useful here, tellg() and tellp(). Function tellg() gives the position of the get pointer in the file and tellp() gives the position of the put pointer in the file.
Suppose the file ‘TEST.DAT’ is open for input, linked with the input stream ifl.
ifl.seekg(50); //will move the get pointer to byte number 50 in the file.
ifl.seekg(25, ios::beg); //will move the get pointer to the 25th byte from the beginning of the file
ifl.seekg(-5, ios::end); //will move the get pointer back 5 bytes from the end of the file
ifl.seekg(12, ios::cur); //will move the get pointer to the 12th byte from the current position
long p=ifl.tellg(); // store position of get pointer in p
ifl.seekg(p,ios::beg); //move get pointer p bytes from the beginning
Suppose the file ‘TEST.DAT’ is now open for output, linked with the output stream ofl.
ofl.seekp(50); //will move the put pointer to byte number 50 in the file.
ofl.seekp(25, ios::beg); //will move the put pointer to the 25th byte from the beginning of the file
ofl.seekp(-5, ios::end); //will move the put pointer back 5 bytes from the end of file
ofl.seekp(12, ios::cur); //will move the put pointer to the 12th byte from the current position
long p=ofl.tellp(); //store position of put pointer in p
ofl.seekp(p,ios::beg); //move put pointer p bytes from the beginning
A. the private members of the class with a pointer to an object.
B. the protected members of the class with a pointer to an object..
C. the public members of the class with a pointer to an object.
D. both private and public members of the class with a pointer to an object.
A pointer can point to only public members of the class. The -> (arrow) operator is used to access class, structure or union members using a pointer. A postfix expression, followed by an -> (arrow) operator, followed by a possibly qualified identifier or a pseudo-destructor name, designates a member of the object to which the pointer points.
A. (.) operator is used.
B. (->) operator is used.
C. (*) operator is used.
D. (&) operator is used.
C++ allows us to have pointers to objects. The arrow operator (->) is used to access members of class using object pointer.
A. self structure
B. base structure.
C. self-referential structure.
D. recursive structure.
Self-reference occurs when a system loops back on itself and describes some aspect of its own form or structure.
A. formal parameters become aliases to the actual parameters.
B. actual parameters become aliases to the formal parameters.
C. formal parameters and actual parameters are same.
D. formal parameters and actual parameters are different.
The called function does not create its own copy of original values.
A. pointer.
B. typedef.
C. reference.
D. identification.
No separate memory is allocated for references.
A. open and rdbuf.
B. put and get.
C. set and reset.
D. seekg and seekp.
ofstream class is derived from ostream class. It is used to write data onto a file. The member functions of ofstream class are open and rdbuf.
A. there is one character conversion format.
B. a character can have one of 256 possible values.
C. data is stored as it is in the memory.
D. characters are stored in ASCII format.
Text files are a sequence of bytes broken into sub-sequences with a special EOL character.It stores information in ASCII characters.
A. existing contents of the file will be discarded.
B. error message displayed if file does not exist.
C. error message displayed if the file has data.
D. file pointer is at the end of the file.
By default, this opens file in ios::trunc mode. This means an existing file is truncated when opened.
A. ios::app
B. ios::out
C. ios::ate
D. ios::binary
It opens file for writing, i.e., in output mode. This also opens the file in ios::trunc mode by default. This means an existing file is truncated when opened, i.e., its previous contents are discarded.
A. iostream.h.
B. fileio.h.
C. fstream.h.
D. ifstream.h.
One must provide the mode explicitly when using an object of fstream class.
A. By default, in C++, files are considered to be binary files.
B. A file can be opened using the constructor of the stream class.
C. To close a file, we disconnect it from the stream.
D. After disconnecting the file, the stream still exists.
Files are stored in two ways: Binary files and text files. A binary file is just a file that contains information in the same format in which the information is held in memory.
A. get( ).
B. getline( ).
C. read( ).
D. input( ).
The read() command can handle the entire structure of an object as a single unit, using the computer's internal representation of data.
A. fstreambase.
B. iostream.
C. filebuf.
D. streambase.
A stream is an abstraction that represents a device on which input and output operations are performed.
A. is like an interface between the program and the file.
B. provides data from the file into the program.
C. opens the file, by default, to take data.
D. cannot be used for sequential operations.
Three streams exist: cout (terminal output), cin (terminal input), and cerr (error output, which also goes to the terminal).
A. closestr().
B. closefile().
C. closef().
D. close().
The close() function closes the stream and also closes all the opened stream files.
A. writes data into the file.
B. reads data from the file.
C. reads bytes randomly.
D. exists only for binary files.
Input stream is a sequence of control statements and data submitted to a system from an input unit.
We check for End-Of-File to prevent an attempt to read, in case the file pointer has reached the end of the file.
Input-Output error handling functions are -
(a) int bad()
(b) int fail()
The classes used are ifstream, ofstream and fstream.
A stream is a sequence of bytes or flow of data. It acts as an interface between the file and program.
In sequential files, records are stored one after the other in sequence. To read any record, all the preceding records must be read. In case of random access, the read operation takes place exactly where the record is to be accessed. To calculate the exact address in memory, a key field is transformed into the relative address.
fstream.h provides simultaneous input and output through ifstream and ofstream respectively.
ifstream - Open the file for input
ofstream - Open the file for output
The function eof() is used to detect an end of file. It returns a non zero value when end of file is reached. Another way to check for end of file is whether the stream object returns zero or not. It returns zero when the end of file is reached.
ifstream fin;
fin.open(“Items.Dat”, ios::in|ios::binary);
while(fin) //as long as it is non zero
{ fin.read((char *)& I, sizeof(ITEM));
………..
}
A file can be opened in two ways :-
a) Using the constructor of the stream class – This method is useful when only one file is used in the stream. Constructors of the stream classes ifstream, ofstream and fstream are used to initialize the file stream object with the file name.
For example, to open a file Names.Dat for reading i.e. input, we create a stream object of class ifstream and pass on the filename to it, as follows –
ifstream read_file(“Names.Dat”);
b) Using the function open() - This method is useful when we want to use different files in the stream. If two or more files are to be processed simultaneously, separate streams must be declared for each.
ifstream ifl; //input stream ifl created
ifl.open(“Names.Dat”); // file Names.Dat linked with ifl
Now using ifl, the file can be read.
ios::nocreate mode causes the open() function to fail if the file does not already exist. It will not create a new file with that name.
A. null pointer.
B. address variable.
C. pointer variable.
D. function pointer.
It is the variable that stores the reference to another variable.
A. malloc( ) and calloc( ).
B. new( ) and delete( ).
C. malloc( ) and delete( ).
D. new( ) and calloc( ).
The operator new( ) is used for memory allocation, whereas delete( ) is used for memory deallocation.
A. dynamic memory allocation.
B. static memory allocation.
C. free store.
D. dereferencing memory.
The amount of memory required is not known beforehand. When the program executes, i.e., during run time only memory is allocated, then it is dynamic memory allocation.
A. dynamic memory allocation.
B. free store.
C. automatic memory allocation.
D. static memory allocation.
Here, the computer knows the length of an integer variable, which is 2 bytes. So, 2 bytes internal memory will be allocated to the variable c during compilation itself.
A. dynamic memory allocation.
B. free store.
C. static memory allocation.
D. automatic memory allocation.
The amount of memory to be allocated is known beforehand, and allocated during compile time, then it is static memory allocation.
A. stack.
B. heap.
C. reserved area.
D. free store.
The heap memory area is a region of free memory, from which chunks of memory are allocated via C++’s dynamic memory allocation functions.
A. must be the same as that of the data member it points to.
B. should be different than that of the data member it points to.
C. may or may not be same as that of the data member it points to.
D. is always float type.
A pointer points to a data member of an object and its data type is always same as that of the data member.
A. array elements are always allocated first 10 memory locations.
B. array elements are always allocated last 10 memory locations.
C. array elements are always allocated randomly 10 memory locations.
D. array elements are always allocated contiguous 10 memory locations.
This declaration is for an array of 10 int pointers; so contiguous memory would be allocated for 10 int type pointers.
A. explicitly passed to the member functions.
B. implicitly passed to the member functions.
C. referred to the member functions.
D. called by the class data types.
When a member function is called, this pointer is automatically passed as an implicit (built -in) argument that is pointer to the object that invoked the function. This pointer is called 'this'.
A. initialized pointers.
B. wild or uninitialized pointers.
C. virus pointers.
D. referenced pointers.
It is easy to use pointers incorrectly, causing bugs that are difficult to find, and which can crash a computer.
A. static member functions only.
B. friend functions only.
C. static member functions and friend functions.
D. virtual functions and friend functions only.
The friend functions are not the members of a class, and therefore, are not passed as this pointer. Similarly, the static member functions do not have a this pointer.
A. object pointer.
B. current pointer.
C. function pointer.
D. this pointer.
this pointer refers to the current object we are working on.
A. call by value.
B. call by reference.
C. call by address.
D. call by name.
In this method, the called function works with, and manipulates its own copy of arguments.
A. Pointer cannot be used in assignment statement.
B. ip is a pointer and cannot be used as integer.
C. Pointer should not be initialized.
D. Pointer cannot be equal to zero.
A pointer points to the address of a variable. It cannot be used as an integer.
A. 10 10 10 10.
B. 10 5 20 20.
C. 5 10 10 10.
D. 10 10 20 20.
j is a reference to i. If, we assign value of p to j, then value of i also changes.
A. abc xyz abc xyz.
B. abc abc abc xyz.
C. abc abc xyz xyz.
D. abc abc abc abc.
Value of p is assigned to pointer q . So, initially *p and * q will have same value.
A. This is correct.
B. It would give an error as ‘a’ cannot be assigned to ‘b’.
C. It would give an error as ‘b’ cannot be assigned to ‘a’.
D. Error in statement 3 and 4.
In C++, void pointer cannot be assigned to the pointer of any type. This would give an error of type mismatch. It can be made true when we explicitly typecast it, b=(char*) a;
A. A reference can be used without proper initialization.
B. Array of references is legal in C++.
C. char, int pointers can refer to null pointers but null pointers cannot refer to other pointers.
D. Array of pointers is not legal in C++.
A reference has to be properly initialized, otherwise it will result in an error. In C++, special care is taken for assignment of void pointers to other pointer types. While we can assign a pointer of any type to a void pointer the reverse is not true until we do explicit typecasting.
A. float p (int *a, int *b, int *c);
B. float * p (int *a, int *b, int *c);
C. float * p (int a, int b, int c);
D. float * p *(int a, int b, int c);
It cannot take integer arguments.
A. double p (int, int, int );
B. double * p (int, int, int ):
C. int * p (double, double, double);
D. double * p (int, int, int );
Here, p is a pointer to a function.
A. an array of integers terminated by a null (‘0’).
B. an array of characters started by a null (‘0’).
C. an array of characters terminated by a null (‘0’).
D. an array of characters and integers.
A string is a one-dimensional array of characters, and is terminated by null (‘ 0’).
A. an index rather than an element pointer.
B. an element pointer rather than an index.
C. an index rather than using data structure trees.
D. trees rather than queues.
Using pointers, for accessing array elements fastens the process.
A. int &ip[10];
B. int *ip[10];
C. int [10];
D. int *ip(10);
Pointers also, may be arrayed like any other data type. After the declaration, contiguous memory would be allocated for 10 pointers that can point to integers.
A. the first element of the array.
B. the last element of the array.
C. any arbitrary element of the array.
D. the second element of the array.
C++ treats the name of an array, as if it were a pointer, i.e., memory address of some element.
A. memory allocatin.
B. memory deallocation.
C. memory use.
D. memory leaks.
The memory allocated through new() must be properly deleted through delete(), otherwise it leads to leakage of memory. We should make sure the memory allocated through new must be properly deleted through delete.
A. new.
B. malloc.
C. create.
D. value.
The new keyword allocates memory for an object or array of objects of type-name from the free store and returns a suitably typed, nonzero pointer to the object.
A. a;
B. val(a);
C. *a;
D. &a;
* is a value at an address operator. Thus, it displays the value pointed by pointer a.
A. address of a.
B. reference operator.
C. pointer.
D. scanning the value of a.
The reference operator & is placed before a variable to declare a reference variable. Example: int sum; int &s=sum; Here s is a reference variable of sum, so s is pointing on the reference of sum variable.
A. *a;
B. .a;
C. &a;
D. address(a);
The operator & is used to find the address associated with a variable. The syntax of the reference operator is as follows: &variablename.
A. free.
B. delete.
C. clear.
D. remove.
The delete operator deallocates a block of memory. The argument must be a pointer to a block of memory previously allocated for an object created with the new operator. The delete operator has a result of type void and therefore does not return a value.
A. int x;
B. int &x;
C. ptr x;
D. int *x;
In order to define pointer variables, the programmer must use the operator denoted as * in C++. The symbol * when placed before a pointer variable means that it as a pointer to.
A. multiplication and division.
B. addition and subtraction.
C. multiplication only.
D. addition and division.
In pointer arithmetic, all pointers increase and decrease by the length of the data.
A. < stdio.h >.
B. < iostream.h >.
C. < stddef.h >.
D. < conio.h >.
A null pointer has a reserved value, often but not necessarily the value 0, indicating that it refers to no object.
A. *.
B. ->.
C. &.
D. <<.
Using a pointer, we can directly access the value stored in the variable, which it points to.
A. *.
B. ->.
C. &.
D. <<.
It is also called as the reference operator or address of operator.
A. double *p;
B. double p;
C. double p*;
D. double p;
Here p is a pointer, which holds the memory address of a float value.
A. reference pointer.
B. function pointer.
C. empty pointer.
D. an object pointer.
We can increment and decrement an object pointer.
A. reference pointer.
B. function pointer.
C. an instance.
D. temporary instance.
A temporary instance is the one which lives in the memory as long as it is being used or referenced in an expression and after it dies. The temporary instances are anonymous.
A. compile time error.
B. deallocation of memory from null pointer.
C. run time error.
D. no error.
If this error is left unhandled, it can cause termination of the program immediately.
A. int &p.
B. int*p.
C. int p.
D. int p*.
Here p is a pointer variable, which holds the address of integer data.
A. the third argument is not given.
B. length of line is 80 but n is 20.
C. line should be a character array.
D. getline() cannot be used without a file.
The correct statement is char line[80];
It will read characters into line until either 80 characters are read or '&' character is encountered, whichever occurs earlier.
A. one.
B. two.
C. three.
D. many.
One to read from original file and the other to write to a new file.
A. ifl.tellg(ios::end, -50);
B. ifl.seekg(50, ios::beg);
C. ifl tellp(50);
D. seekp(50,ios::beg);
seekg() moves the get_pointer to a particular position from the beginning of the file.
The ios::out file mode opens file for writing, i.e., in output mode. This also opens the file in ios::trunc mode, by default. This means an existing file is truncated when opened i.e., its previous contents are discarded. It will open a file in the append mode if the file exists and will abandon the file opening operation if the file does not exist. B. read as many bytes as the size of oa from the address of oa in memory and store in file. C. read characters at the address of oa and store in memory. D. read characters at the address of oa in the file and store in memory. To read and write blocks of binary data, we use read() and write() functions. When we associate a stream with a file, either by initializing a file stream object with a file name or by using the open() method, we can provide a second argument specifying the file mode, as mentioned below: B. to provide operations common to file streams. C. to provide output operations. D. to provide support for simultaneous input and output operations. The file stream class filebuf contains close() and open() member functions in it. B. to set file buffers to read and write. C. to provide operations common to file streams. D. to provide output operations. Being an output file stream class, it provides output operations. It inherits put() and write() functions along with functions supporting random access(seekp() and tellp()) from ostream class defined inside iostream.h file. B. ifl.close(); C. ifstream close(ifl); D. ifstream.ifl close(); A file is closed by disconnecting it with the stream, it is associated with. The close() function accomplishes this task and it takes the following general form:
B. that file name is a reserved word. C. that there is no file in opening mode. D. there is a dot between ifstream and ifl. In order to create file streams, the header file fstream.h is included in the program. For File-to-Memory (i.e. input) type of link, ifstream class type's stream is declared. B. to provide operations common to file streams. C. to provide support for simultaneous input and output operations. D. to provide output operations. It is an input-output file stream class. It provides support for simultaneous input and output operations. It inheirts all the functions from istream and ostream classes through iostream class defined inside iostream.h file. B. get(). C. put(). D. write(). Since, the data in a file of integers stores data in binary format, so the function read() is used. B. open an output file named PRN. C. use the class iofprint. D. cannot be done in C++. To print the output of a program on printer, open file"PRN" as an output file and write contents on it. B. 4. C. 2. D. 1. The ios::app causes all output to that file to be appended to the end. This value can be used only with files capable of output. B. vi v iv iii ii i C. iii i v ii vi iv D. iii i iv ii v vi To insert a record in a sorted file, firstly its appropriate position is determined and then records in the file prior to this determined position are copied to temporary file, followed by the new record to be inserted and then the rest of the records from the file are also copied. B. iv iii ii i C. i iv ii iii D. iv i iii ii To delete a record, following procedure is carried out: B. add it at the end and sort again. C. first determine the position where it is to be added. D. first search the file with the records. To insert a record in a sorted file, first, its appropriate position is determined.Then the records prior to determined position are copied to a temporary file. New record is entered in temporary file and then rest of the records are copied. B. at end of file, function eof() returns 0 C. tellp() returns the position of the put pointer D. to move the put pointer 10 bytes ahead, give fl.seekp(10,ios::beg) In C++, random access is achieved by manipulating seekg(), seekp(), tellg() abd tellp() functions. The seekg() and tellg() functions allow us to set and examine the get_pointer and the seekp() and tellp() functions perform these operations on the put_pointer. B. get(). C. eof(). D. put(). The seekg() allow to set and examine get_pointer. This function is for input streams. B. bad( ). C. fail( ). D. clear( ). clear() function is one of the error-handling function that resets the error state so that further operations can be attempted. B. mapped file. C. random file. D. indirect file. Random access files consist of records that can be accessed in any sequence.This means the data is stored exactly as it appears in the memory. It saves the processing time when read and write operation performed on the file. B. istream. C. ostream. D. ofistream. The fstream is an input-output file stream class. It inherits all the functions from istream and ostream classes through iostream class defined inside iostream.h file. B. getdata( ). C. getline( ). D. getch( ). The prototype of getline() function is -
istream & getline(char *buf, int num, char delim = 'n');
The function getline() reads characters from input stream and puts them in the array pointed to by buf until either num characters have been read, or the character specified by delim is encountered. B. record. C. file. D. table. A record is a collection of interrelated data,i.e.,related fields. B. text file. C. binary file. D. octal file. The data in the text file is stored in the form of readable characters while the data in the binary file is in the form of binary format, i.e., 0 and 1. B. memory-to-file. C. memory-to-memory. D. file-to-file.
A. ofl.open(DAT
A.Dat, iosSOLUTION
ofstream ofl;
ofl.open(filename, ios::app
B. open the given file in append mode, if it exists.
C. open the file if it exists, delete all contents.
D. create the file if it does not exist, open it in append mode.
Right Answer is: BSOLUTION
fl.read((char*)&oa, sizeof(oa));
A. read as many bytes as the size of oa from the file and store in memory at the address of oa.SOLUTION
The prototype of read() function is -
istream &read( (char*) & buf, int sizeof(buf));
The read function reads sizeof(buf) (it can be any other integer value also) bytes from the associated stream and put them in the buffer pointed to by buf.
This function takes two arguments. The first is the address of variable buf and the second is the length of that variables in bytes. The address of the variable must be type cast to type char* (i.e., a pointer to character type).
ofl.open(“items.lst” ios::in
B. ofl.open(“items.lst” || ios::in|| ios::out);
C. ofl.open(“items.lst”, ios::in| ios::out);
D. ofl.open(“items.lst” :: ios::in|| ios::out);
Right Answer is: CSOLUTION
stream_object.open("filename", (filemode));
The second argument of open(), the filemode, is of type int.
We can combine two or more filemode constants using the C++ bitwise OR operator (|).
For example, ofl.open(“items.lst”, ios::in | ios::out);
A. to set file buffers to read and write.
SOLUTION
A. to provide support for simultaneous input and output operations.
SOLUTION
close(ifl); //ifl is input stream
A. ifl close(); SOLUTION
stream_object.close();
ifstream.ifl(“OPEN.DAT”);
A. that function open() is not there.SOLUTION
For example -
ifstream ifl(OPEN.DAT");
A. to set file buffers to read and write. SOLUTION
A. read().SOLUTION
A. declare a stream named PRN.SOLUTION
void main()
{
char ch='A';
fstream ofl("Pur.dat",ios::app);
ofl<< ch;
int p = ofl.tellg();
cout << p;
}
If the file content before the execution of the program is the string "ABC" (Note that " " are not part of the file), the output will be
A. 3.SOLUTION
i) open the data file and a new file
vi) write records with code greater than new code
A. i ii iii iv v viSOLUTION
i) open the data file and a new file
ii) delete the data file and rename the new file
A. i ii iii ivSOLUTION
a. Firstly, determine the position of the record to be deleted, by performing a search in the file.
b. Keep copying the records other than the record to be deleted in a temporary file, i.e., temp.dat.
c. Do not copy the record to be deleted to temporary file, temp.dat.
d. Copy rest of the records to temp.dat.
e. Delete original file, i.e., item.dat as : remove("item.dat");
f. Rename temp.dat as item.dat as : rename("temp.dat", "stu.dat");
A. re-enter all records in proper order.SOLUTION
A. tellg() positions the pointer for reading SOLUTION
A. seekg(). SOLUTION
A. eof( ).SOLUTION
A. direct file.SOLUTION
A. fstream.SOLUTION
A. get( ).SOLUTION
A. field.SOLUTION
A. data file.SOLUTION
A. file-to-memory.