title: Read from stdin and store values into array C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6566856/how-to-convert-a-2d-char-array-to-a-2d-int-array">How to convert a 2d char array to a 2d int array?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to read input from stdin and stop reading when encountering <code>EOF</code>. I need to store these values as integers in a 2x2 array, <code>array[i][j]</code>. </p>
  
  <p>I'm reading in 81 Sudoku characters (integers) from a single line + 2 more characters (<code>\n</code> and <code>EOF</code>) for a total of 83.</p>
  
  <p>Ex:</p>
  
  <p><code>STDIN -- &gt; 123414292142341......2\n &lt;EOF&gt;</code></p>
  
  <p>How do I only store the numbers in each <code>array[i][j]</code>? and stop reading in when I encounter an <code>&lt;EOF&gt;</code> ? </p>
  
  <p>So, after every 9 ints, I need to increment j to get the next row.</p>
  
  <p>I'm looking to do this in C++</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>I have tried this so far</p>
  
  <p>//Read in single line of 83 characters (81 sudoku integers + \n and 
  //Store each integer into array of corresponding row and column</p>
  
  <pre><code>#include iostream
  
  using namespace std;
  
  string input_line;
  
  int main()
  {
  
    while(cin) {
      getline(cin, input_line);
    };
  
  
    return 0;
  }
  </code></pre>
  
  <p>How do I tokenize the string "input_line" into a character of integers? and then to atoi to convert to int, and then finally store them in the Sudoku array??</p>
  
  <hr>
  
  <p>OK, thanks almost done. but I now keep getting an invalid conversion from 'char' to 'const char*' error!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdlib.h&gt;
  
  using namespace std;
  
  string input_line;
  
  int main()
  {
  
    char buffer[9][9];
    int sudoku[9][9];
  
    int v;
  
    cout &lt;&lt; "Enter input: " &lt;&lt; endl;
  
    cin &gt;&gt; (char*)buffer;
  
    for(int i = 0; i &lt; 9; i++)
          for(int j = 0; j &lt; 9; j++)
                  v = atoi(buffer[i][j]);
                  sudoku[i][j] = v;
  </code></pre>