title: How to bubble sort a string?
body: <p>I am trying to get an input from the user and bubble sort that input then output the result. My code:</p>
  
  <pre><code>    #include&lt;iostream&gt;
      using namespace std;
      class bubble
      {
      public :
  
          string arr[20];
  
          //Number of elements in array
          int n;
  
          //Function to accept array elements
          void read()
          {
              while(1)
              {
                  cout&lt;&lt;"\nEnter the number of elements in the array:";
                  cin&gt;&gt;n;
                  if(n&lt;=20)
  
                      break;
                  else
                      cout&lt;&lt;"\n Array can have maximum 20 elements \n";
              }
              //display the header
              cout&lt;&lt;"\n";
              cout&lt;&lt;"----------------------\n";
              cout&lt;&lt;"Enter array elements \n";
              cout&lt;&lt;"----------------------\n";
  
              //Get array elements
              for( int i=0; i&lt;n ;i++ )
              {
                  cout&lt;&lt;"&lt;"&lt;&lt;i+1&lt;&lt;"&gt; ";
                  cin&gt;&gt;arr[i];
              }
          }
          //Bubble sort function
          void bubblesort()
          {
              for( int i=1;i&lt;n ;i++ )//for n-1 passes
              {
                  //In pass i,compare the first n-i elements
                  //with their next elements
                  for( int j=0; j&lt;n-1; j++)
                  {
                      if(arr[j] &gt; arr[j+1])
                      {
                          string temp;
                          temp = arr[j];
                          arr[j] = arr[j+1];
                          arr[j+1] = temp;
  
                      }
  
                  }
              }
          }
          void display()
          {
              cout&lt;&lt;endl;
              cout&lt;&lt;"----------------------\n";
              cout&lt;&lt;"Sorted array elements \n";
              cout&lt;&lt;"----------------------\n";
              for( int j=0; j&lt;n; j++)
                  cout&lt;&lt;arr[j]&lt;&lt;endl;
          }
  };
  int main()
  {
      //Instantiate an instance of class
      bubble list;
      // Function call to accept array elements
      list.read();
      // Function call to sort array
      list.bubblesort();
      //Function call to display the sorted array
      list.display();
      return 0;
  }
  </code></pre>
  
  <p>The code is running fine, but it doesn't accept the value of whitespace or indent in the string as an input. Is there a way to make it accept these values?</p>