title: C++ , 1 cin enter everything for array
body: <p>this is my code about bubble sort.</p>
  
  <pre><code>#include "stdafx.h"
  
  #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  
  using namespace std;
  
  void swap(int &amp;a, int &amp;b) {
      int * x = &amp;a;
      int * y = &amp;b;
      int tmp = * x;
      * x = * y;
      * y = tmp;   
  }
  
  
  int main()
  {
      // INPUT
      int size;
      int i=0;
      int A[80];
      cout &lt;&lt; "How many number in your list A ? ";
      cin &gt;&gt; size;
      for(i=0;i&lt;size;i++) {           
          cout &lt;&lt; " A[" &lt;&lt; i &lt;&lt; "] = " ;
          cin &gt;&gt; A[i];
      }
  
      // PRINT LIST
      cout &lt;&lt; "This is your list number: ";
      cout &lt;&lt; endl;
      for(int i=0; i&lt;=size -1;i++) {
          cout &lt;&lt; A[i] &lt;&lt; " ";
      }
  
  
      // WHILE LOOP , continue if swapped;
      bool swapped = true;
      int pass=0;
      while(swapped == true) {
          swapped = false;
          // Increase Pass
          pass++;
          cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Pass " &lt;&lt; pass &lt;&lt; ":";
          // Loop size - Pass;
          for( i=1; i&lt;=size - pass;i++) {
              // check if X &gt; Y
              if(A[i-1] &gt; A[i]) {
                  // true, doing swap
                  swap(A[i-1], A[i]);
                  // set swapped to continue next loop
                  swapped = true;
              }       
              // Print list again after sort;
              cout &lt;&lt; endl;
              for(int i=0; i&lt;=size -1;i++) {
                  cout &lt;&lt; A[i] &lt;&lt; " ";
              }
  
  
          }               
      }
  
      // PRINT after sort;
      cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Your list after sort: ";       
      for(int i=0; i&lt;=size -1;i++) {
          cout &lt;&lt; A[i] &lt;&lt; " ";
      }
      cout &lt;&lt; endl;
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>On this code,i must enter number of amount (size), and then enter each of A[i].
  But I want to improve this code, can i don't need to enter amount (size), and just cin the the whole A?</p>
  
  <p>Like: </p>
  
  <pre><code>Please enter your list number: 5 1 4 2 8 [enter]
  </code></pre>
  
  <p>And I get the whole A[];</p>
  
  <p>Just a idea after see first answer. I see, Vector can automatic resize, but if I change into vector, will have any way to enter 1 line ? I just got an idea, I enter a string of number: 1 2 3 4 5, then I enter. do C++ have any function to split by space, and then return back to an array or a vector ? in PHP, I just use $array = explode(" ",$string); >_&lt;</p>
  
  <p>Thanks your help, tried to read many article >_&lt;</p>