Well, it works for me when I use code::blocks on windows.
Depending on your system configuration and the way you run the program, then the program may default to using the same folder as the executable (.exe program) for the current working directory.
On my system, the executable is nested two levels deep inside folder bin\Debug. The first step would be to check what is the current working directory.
If necessary you might then either change the program's current working directory, or alternatively change the text of the file name to specify the required path.
This code is for windows. It displays the current working directory. Then attempts to change to one level higher:
for this sort of thing, if it isnt portable code, I often just let the OS do it by calling mv (unix) or ren (windows) through the shell (system() or any of a half dozen others).