that code should work.
but you should pay attention to some points:
1. make sure the file exists, and is in the current directory of your
program.
if you are using a debugger it might be a working dir of the project.
2. make sure the file is not in use by another application.
if you checked this, try to open the file using ios::in and
ios::nocreate flags and after the call check ios::failbit flag. if it
is set, one of 3 things have happened: the file is not found, the
filebuf object already attached to an open file or a filebuf call
fails.
anyway, if you are using windows, try the win32api CreateFile or
OpenFile to get an extended error report.
for future errors, try look at the documentation of the function to
find out how errors are reported the the reasons for the errors.