title: passing string to template function
body: <p>I use template to do generic binary search, but in string case I cannot get the result. I cannot get only string type result.
  please help me out to understand Thanks!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  template &lt;class T&gt;
  T binarySearch(T arr[], int left, int right, T x)
  {
       if(right &gt;= 1)
      {
          int mid = (left + right)/2;
          if(x == arr[mid])
          {
              return mid;
          }
          //right side of array
          else if(x &gt; arr[mid])
          {
              return binarySearch(arr,mid+1,right,x);
          }
          //left side of array
          else
          {
              return binarySearch(arr,left,mid-1,x);
          }
      }
      else
          return -1;
  }
  
  int main()
  {
       int intArr[11] = {0,1,2,3,4,5,6,7,8,9,10};
       double doubleArr[11] = {1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0};
       string stringArr[11] = {"abc", "bcd", "cde", "def", "efg", "fgh", "ghi", "hij", "ijk", "jkl", "klm"};
       int length = sizeof(intArr)/sizeof(intArr[0]);
       cout &lt;&lt; "binarySearch&lt;int&gt;(intArr,0,length,9): " &lt;&lt; binarySearch&lt;int&gt;(intArr,0,length,9) &lt;&lt; endl;
       cout &lt;&lt; "binarySearch&lt;double&gt;(doubleArr,0,length,1.3): " &lt;&lt; binarySearch&lt;double&gt;(doubleArr,0,length,1.3) &lt;&lt; endl;
       string s = "cdf";
       cout &lt;&lt; "binarySearch&lt;string&gt;(stringArr,length,cdf): " &lt;&lt; binarySearch&lt;string&gt;(stringArr,0,length,s) &lt;&lt; endl;
  }
  </code></pre>