77.4k views
3 votes
Which of the following statements opens the file info.txt for both input and output? a) dataFile.open("info.txt", ios::in && ios::out); b) dataFile.open("info.txt", ios::in , ios::out); c) dataFile.open("info.txt", input || output); d) dataFile.open("info.txt", ios::in | ios::out);

User Pran
by
5.4k points

2 Answers

6 votes

Answer:

D

Explanation: Choice D

User Rishit Dagli
by
5.5k points
2 votes

Answer:

Correct answer is D

Step-by-step explanation:

open is a function in c++ programming language used to interact with files.The function takes two parameters as input

  1. File name
  2. mode

File Name

File name is a string name of file to be opened.This is a compulsory parameter for open method.

Mode

Mode is an optional parameter in open function.Following are the accepted values of mode parameter

Prefix ios:: is added to start of each

  1. in (Open file in input mode for writing data to file)
  2. out (Open file in output / read-only mode to read data from file)
  3. binary (Open file in binary format)
  4. ate (Set the starting point of file to the end of file. Default starting point of file is start of file)
  5. "trunc" (If file is opened multiple times all previous data is replaced with new data)
  6. app (All operations of output are performed the end of file)

Use | operator to use multiple modes at a time.

User DavidL
by
5.1k points