问题
填空题
设文件temp.txt 已存在,则以下的打印结果是 【15】 #include <iostream> #include <fstream> using namespace std; int main() { ofstream outf ("temp.txt",ios base: :trunC) ; outf<<"How you doing"; outf.close(); ifstream inf("temp.txt"); char str[20]; inf>>str; inf.close(); cout<<str; return 0; }
答案
参考答案:How
解析: 本题考核文件的I/O操作。程序中定义了ofstream类的对象outf和ifstream类的对象inf。然后利用对象outf在文件test.txt中写入“How you doing”。最后利用对象inf打开文件,将其中的数据输入到变量str中,由于读时遇到空格时就终止,所以str中存放的字符串为“How”。