Q: By default, all the files in C++ are opened in _________ mode.
Solution: By default, all the files in C++ are opened in text mode. They read the file as normal text.
Q: What is the use of ios::trunc mode?
Solution: In C++ file handling, ios::trunc mode is used to truncate an existing file to zero length.
Q: Which of the following is the default mode of the opening using the ofstream class?
Solution: By default, the file is opened in ios::out mode if the file object we are using is of ofstream class.
Q: What is the return type open() method?
Solution: open() method returns a bool value indicating whether the file is opened or some error has occurred.
Q: Which of the following is not used to seek file pointer?
Solution: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file. ios::curr from the current position. ios::beg from the beginning.
Q: Which of the following is the default mode of the opening using the ifstream class?
Solution: By default, the file is opened in ios::in mode if the file object we are using is of ifstream class.
Q: Which of the following is the default mode of the opening using the fstream class?
Solution: By default, the file is opened in ios::in|ios::out mode if the file object we are using is of fstream class.
Q: Which function is used in C++ to get the current position of file pointer in a file?
Solution: C++ provides tell_p() function to get the current position of the file pointer in a file.
Q: Which function is used to reposition the file pointer?
Solution: seekg() function is used to reposition a file pointer in a file. The function takes the offset and relative position from where we need to shift out pointer.
Q: Which of the following is used to move the file pointer to start of a file?
Solution: ios::beg is used to reposition the file pointer to the beginning of the file. It is whenever you want to reposition the pointer at the beginning from any point to the start of the file.
You Have Score    | /10 |