问题 单项选择题

以下不能正确创建输出文件对象并使其与磁盘文件相关联的语句是

A.ofstream myfile;myfile.open("d:ofile.txt");

B.ofstream*myfile=new ofstream;myfile->open("d:ofile.txt");

C.ofstream myfile("d:ofile.txt");

D.ofstream*myfile=new("d:ofile.txt");

答案

参考答案:D

解析: 本题考查文件对象的创建方法。可以直接定义文件对象,也可以用new来动态生成。很明显,选项D中使用new的方式是错误的。

选择题
推断题