已知:int ans,以二进制方式将ans的值写入输出流文件对象outfile中,下列选项中正确的语句是
A.ofstream outfile(“result.txt”,ios::out|ios::binary);outfile.write((int*)&ans,sizeof(int)); B.ofstream outfile(“result.txt”,ios::out|ios::binary);outfile.write(char*)&ans,sizeof(int)); C.ifstream outfile(“result.txt”,ios::out|ios::binary);outfile.write((int*)&ans,ans); D.ifstream outfile(“result.txt”,ios::out|ios::binary);outfile.write((char*)&ans,ans);正确答案B