How to read a .txt file using c-strings?
<p>I'm working on a project for school and I need to read in text from a file.</p>

<p>Sounds easy peasy, except my professor put a restriction on the project: <b>NO STRINGS</b>
("No string data types or the string library are allowed.")</p>

<p>I've been getting around this problem by using char arrays; however, I'm not sure how to use char arrays to read in from a file.</p>

<hr>

<p>This is an <b>example</b> from another website on how to read in a file <b>with</b> strings.</p>

<pre><code>// reading a text file
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
using namespace std;

int main () {
  string line;
  ifstream myfile ("example.txt");
  if (myfile.is_open())
  {
    while ( getline (myfile,line) )
    {
      cout &lt;&lt; line &lt;&lt; '\n';
    }
    myfile.close();
  }

  else cout &lt;&lt; "Unable to open file"; 

  return 0;
}
</code></pre>

<p>The important line here is <code>while ( getline (myfile,line) );</code></p>

<p><code>getline</code> accepts an ifstream and a <b>string</b> (not char array).</p>

<p>Any help is appreciated!</p>