title: Debugging C++ code involving use of: vector, string, STL
body: <p>I am C++ beginner. When I try to debug C++ code using following constructs like string, vector of certain native types, STL etc, debugging gets tedious. I use MS Visual Studio 2010/ Visual C++ 2010 Express. </p>
  
  <p>e.g. </p>
  
  <p>-- While using string as below:</p>
  
  <pre><code>string str;
  
  getline(cin, str);
  
  for(i=0; i&lt;str.size();i++)
  </code></pre>
  
  <p>Watch window does not show values for str[i]. It says overloaded operator not found. I have to manually collapse the whole string variable str and see the char elem at that particular index, which gets cumbersome.</p>
  
  <p>-- While using vector as below, same issue. If I set variable v1[k] in watch window same error.</p>
  
  <pre><code>vector&lt;int&gt; v1(100);
  
  
  for(int k=0;k&lt;100;k++)
  {
      v1.push_back(k);
  }
  </code></pre>
  
  <p>-- Tried using simple STL iterators like it.begin() , it.end() and algorithms like sort(), reverse() , I could not debug inside those functions by stepping,  or could not set break point into those.(I know they being inside STL or some such standard library they would be assured to be bug-free, but one can still use them incorrectly by passing something invalid/incorrect)</p>
  
  <p>Coming from C language usage of many years, to C++, I find this lack of 'debug ability' , or some restrictions in that , painful, while I am trying to understand large chunks of C++ code written by someone else, at work. </p>
  
  <p>My questions -</p>
  
  <p>What are effective ways to debug working code to understand its functionality while using idioms like step in, breakpoints, watch point, watch windows. Is any particular debugger better/worse than other.(Like say gdb being better) or are there any specific tricks/tips to aid debugging.</p>
  
  <p>In general how to analyze a C++ code to understand its working? </p>