Can you post a small complete program the compiles, executes and shows the problem?
Its not possible to test the small pieces of code that was posted.