What I edited in is unrelated to your current problem, it's just a different approach to parsing to the one you're using.
But my point about the debugs prints, is that you're not printing ALL your variables each time anything happens. You're just printing what you expect to change. If it's not acting as expected, you're probably doing something unexpected. Doing a complete memory dump of ALL variables, even ones that you don't expect to be affected may trigger an "aha" moment or give you leads towards where the error is. Do a literal entire "stack dump" after literally every little change, and see where something unexpected occurs. Just write a function which does a "core dump" of your entire system, and do one of those after each instruction, see where things go off the rails. For example, input 1 to "w", then dump all variables, then set "X=W+0", then dump all variables again. And so on, with different inputs and amounts.
EDIT: Note how you said bits of some strings are missing. That may indicate that your tokenizer isn't actually breaking the tokens at the right places, so it's something to check. Also, cout should always correctly output ints as ints, since it uses operator overloading to always get the correct conversion, thanks to OO. The only issue could be if you're storing something as a string and you didn't properly parse it in the first place.