C++ Out of Subscript Range <p>I'm running a C++ Program that is supposed to convert string to hexadecimals. It compiles but errors out of me at runtime saying:</p> <blockquote> <p>Debug Assertion Failed! (Oh no!)</p> <p>Visual Studio2010\include\xstring</p> <p>Line 1440</p> <p>Expression: string subscript out of range</p> </blockquote> <p>And I have no choice to abort... It seems like it converts it though up to the point of error so I'm not sure what's going on. My code is simple:</p> <pre><code>#include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;string&gt; using namespace std; int main() { string hello = "Hello World"; int i = 0; while(hello.length()) { cout &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; hex &lt;&lt; (unsigned int)hello[i]; i++; } return 0; } </code></pre> <p>What this program should do is convert each letter to hexadecimal - char by char. </p>