Problem creating files greater than 2GB

With the C code I am able to create files greater than 2GB if I use the 64 bit compile option -D_FILE_OFFSET_BITS=64. There I am using the function fprintf to write into the file. But when I use C++ and ofstream the file is getting truncated when the size grows beyond 2GB. Is there any special compile option needed to overcome this?

My OS is - SunOS 5.8

With the GNU gcc compiler, specifying the "-m64" option generates code for the 64-bit environment which includes 8-bytes for a file offset. I normally use low-level I/O with which you can specify the O_LARGEFILE status flag when working in a 32-bit environment.

In short, try compiling with the -m64 option.