1.What is the difference between class/object?
2.Did you think about classes/objects around you since the last session?
3.What library do we need for processing file I/O?
4.What is the class for the input file stream? Give an example
5.What is the class for the output file stream? Give an example
6.Why do you want to use files instead of using input?
7.How do you read from a file? give an example
8.How do you write to a file? give an example
9.What is a member function?
10.How do you catch error in reading /writing files?
11.What happens if you try to open a file for writing which does not exist?
12.How do you append to the end of the file instead of losing your old data?
Hi there, answer the following questions using knowledge from C++
Thank You,
Vincent
1.What is the difference between class/object?
Class : A class is a template for creating objects in program, it a logical entity and no memory is allocated when class is created and declared only once.
Object : The object is an instance of a class, it a physical entity, allocates memory space whenever, can be created multiple times.
Example: Car. Example: Jaguar, BMW, Tesla, etc.
3.What library do we need for processing file I/O?
The ANSI C standard provides IO functions into (stdio.h).
C++ continues this and it also IO in libraries iostream and fstream.
4.What is the class for the input file stream? Give an example
The istream class
It provides formatted input and unformatted input.
// for scanning a single char
cin.get(ch);
cout << ch;
5.What is the class for the output file stream? Give an example
The ostream Class :
It provides two output functions: formatted output and unformatted output.
// single char onto the screen.
cout.put(ch);
7.How do you read from a file? give an example
Information from a file is read using the stream extraction operator (>>).
The only difference is that you use an ifstream or fstream object instead of the cin object.
// write inputted data into the file.
outfile << data << endl;
8.How do you write to a file? give an example
Information to a file from your program using the stream insertion operator (<<).
The only difference is that you use an ofstream or fstream object instead of the cout object.
// write inputted data into the file.
outfile << data << endl;
9.What is a member function?
Member functions are the functions, which have their declaration inside the class definition and works on the data members of the class.
infile >> data;
cout << data << endl;
11.What happens if you try to open a file for writing which does not exist?
Opening a file for reading fails if the file does not exist.
If file_name does not exists, no exception is thrown. We need to handle the case to throw exception.
Get Answers For Free
Most questions answered within 1 hours.