title: C++ - Attempting to use string functions to reverse an input string
body: <p>As part of a homework assignment I need to be able to take an input string and manipulate it several ways using a list of string functions. The first function takes a string and reverses it using a for loop. This is what I have: </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  namespace hw06
  {
      typedef std::string::size_type size_type;
  
      //reverse function
      std::string reverse( const std::string str );
  
  }
  
  
  // Program execution begins here.
  
  int main()
  {
      std::string inputStr;
  
      std::cout &lt;&lt; "Enter a string: ";
      std::getline( std::cin, inputStr );
  
  
      std::cout &lt;&lt; "Reversed: " &lt;&lt; hw06::reverse( inputStr )
      &lt;&lt; std::endl;
  
  
      return 0;
  }
  
  
  //reverse function definition
  
  std::string hw06::reverse( const std::string str )
  {
  
      std::string reverseStr = "";
  //i starts as the last digit in the input. It outputs its current 
  //character to the return value "tempStr", then goes down the line
  //adding whatever character it finds until it reaches position 0
      for( size_type i = (str.size() - 1); (i &gt;= 0); --i ){
          reverseStr += str.at( i );
      }
          return reverseStr;
  }
  </code></pre>
  
  <p>The program asks for input, then returns this error:</p>
  
  <blockquote>
    <p>terminate called after throwing an instance of 'std::out_of_range'
     what(): basic_string::tat</p>
  </blockquote>
  
  <p>I'm really at a loss as to what I'm doing wrong here. The loop seems correct to me, so am I misunderstanding how to reference the function?</p>