title: String walking throws exception in VS2005 C++
body: <p>I'm using C++ in Visual Studio 2005 (large legacy project).</p>
  
  <p>Have the following code snippet:</p>
  
  <pre><code>bool FOO::bar(const string&amp; input_text)
  {
  
    string::const_iterator
          ch = input_text.begin(),
          last_ch = input_text.end();
  
    for( ; ch!=last_ch; ++ch )
    {  
    /////////////////////////////////////////////////////
          const char a = *ch;
    /////////////////////////////////////////////////////
    }
    return true;
  }
  </code></pre>
  
  <p>When I run this code in debug mode it crashes on the <code>const char a = *ch</code> line and says:</p>
  
  <p>Unhandled exception at 0x0000000140d08b20 in foobar.exe: 0xC0000005: Access violation reading location 0x0000000000000000.</p>
  
  <p>When I run this code in release mode, it runs just fine.</p>
  
  <p>This code is called as follows:</p>
  
  <pre><code>CString full_filter;
  full_filter.Format( "*%s*", filter_value );
  foo.bar((LPCTSTR)full_filter));
  </code></pre>
  
  <p>I am a VS2005 C++ novice, so am looking up what these mean now, but put this in due to questions in comments section.</p>
  
  <p>I have found a number of seemingly related C questions and answers about this.  Based on those, I have tried defining various values for input_text, such as removing it from the parameters and just defining it as </p>
  
  <p><code>string input_text("FOO");</code>
  or
  <code>string input_text = "FOO";</code>
  or
  <code>char[] tmp = "FOO"; string input_text = tmp;</code></p>
  
  <p>All have failed.</p>
  
  <p>I  have also taken the above code snippet and put it into it's own brand spanking new VS2005 project, and it runs just fine.</p>
  
  <p>So, there are some .... unique settings in the legacy VS2005 project that are causing problems.  Any clue what those settings might possibly be, or how to smoke them out?  I'm a rank VS2005 novice.</p>