It's hard to know what you're doing wrong without code. You may wish to create a
Short, Self Contained, Correct (Compilable), Example or
SSCCE. This is a small program that compiles, runs, demonstrates your problem, and contains no extraneous code. Please read the link, and have a go at it. Creating an SSCCE actually serves two purposes, the most obvious being that you can post a short program that we can inspect and run, and help you solve your problem, but the better purpose is that often when you go through this process and are required to isolate your problem and inspect it in all its nakedness, you will experience an "aha" moment and will be able to solve the problem yourself. Best of luck.