35 Lecture
CS201
Midterm & Final Term Short Notes
Streams
In C++, streams are used to perform input and output operations on files, standard input/output devices (such as the console), and other sources/destinations of data. Streams allow for easy reading and writing of data in a variety of formats, in
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
Which header file is used for handling input/output operations in C++? A) iostream B) string C) vector D) algorithm Answer: A
Which of the following is not a standard stream in C++? A) cin B) cout C) cerr D) clog Answer: D
Which operator is used for insertion (output) operation with streams? A) << B) >> C) || D) && Answer: A
Which operator is used for extraction (input) operation with streams? A) << B) >> C) || D) && Answer: B
What is the default mode for file stream in C++? A) read B) write C) append D) binary Answer: A
Which stream is used for handling errors during input/output operations? A) cin B) cout C) cerr D) clog Answer: C
Which function is used to open a file for reading in C++? A) open() B) read() C) write() D) close() Answer: A
Which function is used to close a file in C++? A) open() B) read() C) write() D) close() Answer: D
Which function is used to check if a file is open or not in C++? A) is_open() B) read() C) write() D) close() Answer: A
Which function is used to read a line of text from a file in C++? A) getline() B) read() C) write() D) close() Answer: A
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a stream in C++? Answer: A stream is an abstraction that represents a sequence of data flowing between a program and an input/output device.
What are the three types of streams in C++? Answer: The three types of streams in C++ are input streams, output streams, and error streams.
What is the purpose of using stream manipulators in C++? Answer: Stream manipulators are used to modify the output formatting of streams, such as setting the width or precision of output data.
What is the difference between text mode and binary mode when opening a file stream in C++? Answer: Text mode is used for reading and writing text files, while binary mode is used for reading and writing binary files.
What is the difference between cin and getline() in C++? Answer: cin is used to read input data from the console, while getline() is used to read a line of input data from a file.
How can you open a file for writing in C++? Answer: You can open a file for writing in C++ by calling the open() function with the mode parameter set to "out" or "out | trunc".
What is the purpose of the flush() function in C++? Answer: The flush() function is used to clear the output buffer and ensure that any pending output data is written to the output device.
How can you check if an input operation has failed in C++? Answer: You can check if an input operation has failed by calling the fail() function on the input stream.
How can you read data from a stringstream in C++? Answer: You can read data from a stringstream in C++ by calling the str() function to get the stream's internal string buffer, and then using standard string operations to extract the data.
How can you write data to a file in binary mode in C++? Answer: You can write data to a file in binary mode in C++ by opening the file stream with the mode parameter set to "out | binary", and then using the write() function to write data in binary format.