title: How to fix 'std::logic_error' what(): basic_string::_M_construct null not valid error?
body: <p>I am trying to check whether an input string is alphanumeric or more uppercase or empty. If the input string is among the above-malfunctioned strings, I simply want to return false/0 otherwise work with rest of the program which is working fine. The chunk of my program which is given problem :</p>
  
  <pre><code>std::string myfunc(std::string input){
      std::string b="";
  
      if (!input.size()) return 0;
      for (int i = 0; i &lt; input.size(); i++){
  
          if ( input[i] &lt; 'a' || input[i] &gt; 'z'|| isalpha(input[i]) || isupper(input[i]) ) return 0;
      }
      b = input;
      //just copy the input string for now.
      return b;
  }
  </code></pre>
  
  <p>and I call this function as</p>
  
  <pre><code>int main(){
      std::string input="Somthing";
      std::cout &lt;&lt; myfunc(input)&lt;&lt; std::endl;
      return  0;
  }
  </code></pre>
  
  <p>getting the below error?</p>
  
  <pre><code>terminate called after throwing an instance of 'std::logic_error'
    what():  basic_string::_M_construct null not valid
  Aborted (core dumped)
  </code></pre>
  
  <p>This program runs well without these two edge cases. I am not able to understand the error and find a fix to it? Any suggestions on what I am doing wrong?</p>