title: terminate called after throwing an instance of 'std::logic_error' basic_string::_S_construct null not valid
body: <pre><code>string Solution::findDigitsInBinary(int A) {
      int i, j, rem;
  
      if(A == 0) {
          return 0;
      }
      else {
          string res="";
  
          while(A &gt; 0) {
              rem = A % 2;
              res = res + to_string(rem);
              A = A / 2;
          }
  
          return std::string(res.rbegin(), res.rend());
      }
  }
  </code></pre>
  
  <p>how to resolve this</p>