The following code crashes C++ with a runtime error:
#include
using namespace std;
int main() {
string s = \"aa\";
for (int i = 0; i
Since s.length() is unsigned type quantity, when you do s.length()-3, it becomes negative and negative values are stored as large positive values (due to unsigned conversion specifications) and the loop goes infinite and hence it crashes.
To make it work, you must typecast the s.length() as :
static_cast < int > (s.length())