title: C++ file stream open modes ambiguity
body: <p>For performing file IO in C++ we use the ofstream, ifstream and fstream classes.</p>
  
  <ul>
  <li>ofstream: Stream class to write on files<br/></li>
  <li>ifstream: Stream class to read from files<br/></li>
  <li>fstream: Stream class to both read and write from/to files</li>
  </ul>
  
  <p>The process of associating a file with a stream object is called "opening the file".
  When opening a file we can specify the mode in which the file is to be opened.
  My query is related to the <code>ios::out</code> and <code>ios:in</code> modes.</p>
  
  <p>When I create an <code>ofstream</code> object and open the file with <code>ios::in</code> mode, I am able to
  write into the file but only if its created already(with <code>ios::out</code> mode file is also created if it doesn't already exist). <br> 
  But when I create <code>ifstream</code> object and open the file with <code>ios::out</code> mode, I am able to read from the file.</p>
  
  <p>My question is why these modes (<code>ios::in</code>/<code>ios::out</code>) are supplied by the language when the type of the stream(<code>ifstream</code>/<code>ofstream</code>) itself specifies as to which type of operation(input/output) is being performed ?</p>
  
  <p>Also why this ambiguous usage(<code>ofstream</code> with <code>ios::in</code> and <code>ifstream</code> with <code>ios::out</code>) works in one case and fails(though only if file is not already present) in another ? </p>