title: C++ reading from a text file into a array/string
body: <p>Here is the code I have so far.</p>
  
  <p>What I need to do is read from two different text files, Matrix A and Matrix B. </p>
  
  <p>I can do this however for each text file matrix I read it only comes up with </p>
  
  <pre><code>1 0 0 
  </code></pre>
  
  <p>(so basically the first line) where the whole text file for Matrix A is in fact </p>
  
  <pre><code>1 0 0
  2 0 0
  3 0 0
  </code></pre>
  
  <p>so does anybody know how I can do this?</p>
  
  <p>Thanks!</p>
  
  <pre><code>#include &lt;iostream&gt;  //declaring variables
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  string code(string&amp; line);
  int main()
  {
      ofstream outf;
      ifstream myfile;
      string infile;
      string line;
      string outfile;
  
      cout &lt;&lt; "Please enter an input file (A.txt) for Matrix A or (B.txt) for Matrix B" &lt;&lt; endl;
      cin &gt;&gt; infile;   //prompts user for input file
  
      if (infile == "A.txt")
      {      //read whats in it and write to screen
          myfile.open("A.txt");
          cout &lt;&lt; endl;
          getline (myfile, line);
          cout &lt;&lt; line &lt;&lt; endl;
  
      }
      else
          if (infile == "B.txt")
          {
              myfile.open("B.txt");
              cout &lt;&lt; endl;
              getline (myfile, line);
              cout &lt;&lt; line &lt;&lt; endl;
          }
          else
      { 
          cout &lt;&lt; "Unable to open file." &lt;&lt; endl;
      }
          //{
              //while("Choose next operation");
          //}
      return 0;
  }
  </code></pre>