click below
click below
Normal Size Small Size show me how
M Seven: CP2
File handling Reviewer
| Question | Answer |
|---|---|
| What is the correct syntax for fclose()? | fclose(fp); |
| Writes a set of data to a file | fprintf() |
| The ifstream would be used when: | reading a file |
| Which stream class is to ONLY write on files? | ofstream |
| What is the output of the given program? #include <iostream> using namespace std; int main() { char str[] = "Steve jobs"; int val = 65; char ch ='A'; cout << val << endl; return 0; } | 65 |
| It points to a structure that contains about the file: | File pointer |
| An operation where in data is added to the existing data of file | Append |
| Creates a new file or open an existing file | fopen() |
| What is correct syntax for fopen()? | fp = fopen("one.txt", "w"); |
| File mode that opens or create a text file in writing mode | w |
| Reads a character from a file: | getc() |
| What does the following code do? while( (ch = getchar()) != '/n') { putc(ch,fp); } | Gets a character, put it into a file pointer until an enter is pressed |
| Refers to the name of the file | File name |
| A function directly writes into the file: | fprintf() |
| What is the output of the given program? #include <iostream> using namespace std; int main() { char str[] = "Steve jobs int val = 65; char ch = 'A'; cout << val << endl; return 0; } | Error (no closing quotation mark) |
| A C++ library that allows working with files | fstream |
| Which operator is used to insert the data into the file? | << |
| The ifstream would be used when: | reading a file |
| Which header file is used for reading and writing to a file? | #include<fstream> |
| File mode that opens a text file in append mode | a |
| EOF means ______________________ | End of file |
| What is the correct syntax for declaring a file pointer? | FILE *fp; |
| Writes a character to a file: | fopen() |
| What can be used to input a string with a blank space? | getline |
| What is meant by ofstream in c++? | Writes to a file |
| Closes a file | fclose() |
| What is the return type open() method? | bool |
| By default, all the files in C++ are opened in ________ mode. | Text |
| The ifstream would be used when: | reading a file |
| Which of the following header file is required for creating and reading files? | fstream |
| Which stream class is used to BOTH read and write on files | fstream |
| Which of the following is used to create an output stream? | ofstream |
| It is created for the permanent storage of data | File |
| Which header file is required to use file I/O operations? | <fstream> |
| When will the cin can start processing of input? | After pressing the return key |
| It represents a sequence of bytes on the disk where a group of related data is stored. | File |
| Which member function is used to determine whether the stream object is currently associated with a file? | is_open |
| Which of the following is used to create a stream that performs both input and output operations? | fstream |
| File mode that opens a text in reading mode | r |
| Which of the following is the file pointer? | FILE *fp; |
| Which of the following is NOT a file mode? | w++ |
| Which of the following is a text file? | notes.txt |
| What does the following code do: fp = fopen("one.txt", "r"); while ( (ch = getc(fp))!= EOF) printf("%c",ch); fclose(fp); | Read contents of a file |
| It specifies the purpose of opening the file. | File mode |