title: Can I redirect an ifstream to cin?
body: <p>I have a program that reads input from the terminal and the stream from <code>cin</code> is used in multiple classes for parsing at various levels.  </p>
  
  <p>Instead of using <code>cin</code> for getting the data from the terminal, I want to read in a file that has the information I need to parse, but I don't want to modify all my header and .cpp files to accept an <code>ifstream&amp;</code> parameter.</p>
  
  <p>To keep the existing code in place I'm trying to simply redirect the <code>ifstream</code> to cin, but don't know how.  </p>
  
  <p>So assume I have the following in main:</p>
  
  <pre><code>ifstream inFile("myfile.txt", ifstream::io);
  
  string line;
  while(getline(inFile, line)) 
  {
    char firstChar;
    inFile &gt;&gt; firstChar;
    cout &lt;&lt; firstChar;
    inFile.ios::rdbuf(cin.rdbuf());
    Continue myFile;
  } 
  </code></pre>
  
  <p>In my <code>continue.cpp</code> I'm just doing:</p>
  
  <pre><code>Continue()
  {
     string line;
     cin &gt;&gt; line;
     cout &lt;&lt; "---remaining line: " &lt;&lt; line &lt;&lt; "\n";
  }
  </code></pre>
  
  <p>However it's only printing the first char from main.</p>