title: More elegant way to check for duplicates in C++ array?
body: <p>I wrote this code in C++ as part of a uni task where I need to ensure that there are no duplicates within an array:</p>
  
  <pre><code>// Check for duplicate numbers in user inputted data
      int i; // Need to declare i here so that it can be accessed by the 'inner' loop that starts on line 21
      for(i = 0;i &lt; 6; i++) { // Check each other number in the array
          for(int j = i; j &lt; 6; j++) { // Check the rest of the numbers
              if(j != i) { // Makes sure don't check number against itself
                  if(userNumbers[i] == userNumbers[j]) {
                      b = true;
                  }
              }
              if(b == true) { // If there is a duplicate, change that particular number
                  cout &lt;&lt; "Please re-enter number " &lt;&lt; i + 1 &lt;&lt; ". Duplicate numbers are not allowed:" &lt;&lt; endl;
                  cin &gt;&gt; userNumbers[i];
              }
          } // Comparison loop
          b = false; // Reset the boolean after each number entered has been checked
      } // Main check loop
  </code></pre>
  
  <p>It works perfectly, but I'd like to know if there is a more elegant or efficient way to check.</p>