You have to be more specific. What is it that doesn't work? When you say the .dat format do you mean a particular file format or just a file name that ends with .dat?
int num=50;
file.open("binary.dat", ios::out|ios::binary);
while(j<1)
file.write((char*)&num, sizeof(int)) //this does not write to binary.dat but if i change to bin it writes
How did you know that? Did program finished and nothing is written? Did file existed before? What about bin file? What about permissions? Is there anything preventing your program from creating this file?