title: How can I do file i/o without fstream for competitions like google code jam?
body: <p>Let me preface this question by saying I am not a very experienced programmer.</p>
  
  <p>For competitions like google code jam, I write code like this:</p>
  
  <pre><code>#include &lt;fstream&gt;
  
  using namespace std;
  
  int main() {
      ifstream fin("file.in");
      ofstream oin("file.out");
      //Etc. I'll now write out my solution.
      //...
  }
  </code></pre>
  
  <p>However, I noticed that many other code sources by other participants don't use fstream at all and use iostream instead. Then they'll use cout and cin as if they were reading and writing from the console.</p>
  
  <p>How are they doing this? Can I do the same thing if I am using g++ and ubuntu?</p>
  
  <p><strong>EDIT:</strong> Since it was requested that I post an example of what I mean, here is code from participant ryuuga who solved large <a href="http://code.google.com/codejam/contest/dashboard?c=975485#" rel="nofollow">Bot Trust, Problem A</a> from the recent '11 qualification round.</p>
  
  <p>He uses cin and cout but I don't know how he is doing file i/o.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  #include &lt;cstdio&gt;
  #include &lt;algorithm&gt;
  #include &lt;deque&gt;
  #include &lt;map&gt;
  #include &lt;set&gt;
  typedef pair&lt;int,int&gt; pii;
  #include &lt;vector&gt;
  typedef vector&lt;int&gt; vi;
  #include &lt;queue&gt;
  #include &lt;stack&gt;
  #define For(i,a,b) for(int i=(a);i&lt;(b);++i)
  
  #define ForI(i,a,b) for(int i=(a);i&lt;=(b);++i)
  #define ForAll(it,set) for(typeof(set.begin()) it = set.begin(); it!=set.end(); ++it)
  
  typedef stack&lt;int&gt; si;
  typedef queue&lt;int&gt; qi;
  
  int main(){
      int t;
      cin&gt;&gt;t;
      ForI(tt,1,t){
          int n;cin&gt;&gt;n;
          int pos[2]={1,1}, time[2] = {0,0};
          int curTime = 0;
          For(i,0,n){
              char type; int button;
              cin&gt;&gt;type&gt;&gt;button;
              type = (type=='B'?1:0);
              int nextTime = 1+max(curTime, time[type] + abs(button - pos[type]));
              pos[type] = button;
              time[type] = nextTime;
              curTime = nextTime;
          }
          cout&lt;&lt;"Case #"&lt;&lt;tt&lt;&lt;": "&lt;&lt;curTime&lt;&lt;endl;
      }
  
      return 0;
  }
  </code></pre>