首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include <iostream> #include <fstream> using namespace std; int main() { ofstream ofile("D:\\test.tx
有以下程序: #include <iostream> #include <fstream> using namespace std; int main() { ofstream ofile("D:\\test.tx
admin
2010-03-29
56
问题
有以下程序:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream ofile("D:\\test.txt");
if(!ofile)
{
cout<<"test.txt can’t open"<<end1;
return 0;
}
ofile<<"This book is C++"<<" "<<12345<<end1;
ofile.close();
ifstream ifile("D:\\test.txt");
if ( ! ifile)
{
cout<<"test.txt can’t open"<<end1;
return 0;
}
char str[80];
ifile>>str;
ifile.close();
cout<<str<<end1;
return 1;
}
程序执行后的输出结果是【 】。
选项
答案
This
解析
本题考核文件的I/O操作。程序中的初始化值不能被修改,所以程序最后输出n=10。另外程序中定义了ofstream类的对象ofile和ifstream类的对象 ifile,然后利用对象ofile在文件test.txt中写入“This book is C++12345”。最后利用对象ifile打开文件,将其中的数据输入到变量str中,由于读时遇到空F时就终止,所以str中存放的字符串为“This”。
转载请注明原文地址:https://kaotiyun.com/show/eGjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序#includeintfun(char*s){char*p=s;while(*p!=’\0’)p++;return(p-s);}main(){char*p="01234";printf("%d\n",fun
一棵二叉树共有25个结点,其中5个是叶子结点,则度为1的结点数为
下面叙述中正确的是
在黑盒测试方法中,设计测试用例的根据是
数据流图(DFD)中的有向箭头(→)表示
结构化程序设计的基本原则不包括( )。
在嵌套使用if语句时,C语言规定else总是
函数fun的功能是:统计长整数n的各个位上出现数字1、2、3的次数,并通过外部(全局)变量c1,c2,c3返回主函数。例如:当n=123114350时,结果应该为:C1=3c2=1c3=2。请在程序的下划线处填入正确的内容并把下划线删除,使程序
已知库函数islower(ch)用以判断ch中的字母是否为小写字母,则下列程序运行后的结果是()。#include#includevoidfun(chas*p){inti=0;while(p[i]){if(p[i]==’’&&isl
能从任意一个结点开始没有重复地扫描到所有结点的数据结构是()。
随机试题
Whoeverisinchargeof________theeventmusthavetheabilitytoworkonmultipletasksatthesametime.
分部分项工程量清单应包括项目编码、项目名称、项目特征、计量单位和:[2010年第11题]
会计核算软件按照不同的适用范围可分为通用会计核算软件和商品化会计核算软件。()
仿冒知名商品构成不正当竞争行为应符合的条件不包括()。
学校教育与家庭教育相互配合的方法有()
李某去世后,其子小李继承了李某名下的一处房产,后来小李把房产卖给了朋友。下列选项中正确的是()
Refertotheexhibit.ThenetworkadministratornormallyestablishesatelnetsessionwiththeswitchfromhostA.However,hostAi
数据在计算机存储器上的存储形式主要是______和文件。
若有说明“chars1[30]="abc",s2[]="defghi";”,则在使用函数stcat(s1,s2)后,结果是()。
______(与核能引起的弊端相比),thesolarpowercanserveasabettermovetowardthesolutionfortheproblemofenergycrisis.
最新回复
(
0
)