How to use cin for exit in C++
<p>I have the following code from a book about Algorithms by Robert Sedwick.</p>

<p>How do i break a for loop in the following statement <code>if (!(cin &gt;&gt; a[N])) break;</code> </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;string&gt;

using namespace std;
int compare(const void *i, const void *j)
  { return strcmp(*(char **)i, *(char **)j); }
int main()
  { const int Nmax = 1000;
    const int Mmax = 10000;
    char* a[Nmax]; int N;
    char buf[Mmax]; int M = 0;
    for (N = 0; N &lt; Nmax; N++)
      {
        a[N] = &amp;buf[M];
        if (!(cin &gt;&gt; a[N])) break; 
        M += strlen(a[N])+1;
      }
    // std::cout &lt;&lt; "Number of strings entered are " &lt;&lt; N &lt;&lt; std::endl;
    qsort(a, N, sizeof(char*), compare);
    for (int i = 0; i &lt; N; i++) 
      cout &lt;&lt; a[i] &lt;&lt; endl;
  }
</code></pre>
