   C++ crash unless I have a "cout  endl"
  Alright, this is making no sense to me.  I have a snippet of code:int nodeValue = atoi(mutations.substr(i,3).c_str());char direction = mutations[i+3];cout << endl;if(direction == 'R' || direction == 'r') RotateRight(nodeValue);else if(direction == 'L' || direction == 'l') RotateLeft(nodeValue);This runs fine.  However, if I comment out the line in the middle (cout << endl), it segfaults.  How in the world does printing a newline have any effect on this?For reference, here are the first few lines of RotateRight():  void CSecretDecoderTree::RotateRight(int nodeLabel){ BTNode *center = GetNode(nodeLabel); if(!center) return; // not found BTNode *parent = (*center).m_parent; BTNode *left = (*center).m_left; BTNode *right = (*center).m_right; // I can provide the rest if it is relevant.Can someone help please?   
  The printing is a red herring. You've already caused the damage a long time ago, the print statement just manifests it. You've likely trashed the stack or some random memory somewhere.Unfortunately the problem is probably not in the code you've posted, but elsewhere entirely.Employ your debugger, sanity check the initial values of all inputs and all initial conditions, et cetera.   ;  I understand your logic if my code crashed when it reached the print statement.  But that's not what happens.  The code works perfectly fine with the print statement.  When I TAKE OUT the print statement, it crashes.   ;  And how many bytes of machine code get generated by that print statement? It's quite a lot, and can be enough to move something around in memory enough that the offending bad access doesn't happen in that function any more. Declaring a single variable can cause this to happen in the extreme case.You've stomped on some memory, somewhere. Now you're going to have to track it down. The most local candidate is a statement in the function execution, itself, so start at the beginning of that function and examine the variables you have very carefully, looking for corruption.   ;  Another way of saying what jpetrie is saying is that most likely you are invoking undefined behavior somewhere in your program. This means the program may crash, or it might print "57", or it might even do exactly what you expect it to do, but there are no guarantees.Be happy that you have a way to reproduce the problem (without the `cout << endl;') and you can debug your program.