题目内容 (请给出正确答案)
[单选题]

int f(char fn[]) { fstream file; file.open(fn,ios::in); if(!file) { cout<<fn<<"打不开"<<endl; exit(1); } char ch; int i="0;" while(!file.eof()) { file.get(ch); i++; file.close(); return i-1; 上述函数的功能为(>

A.读取指定文件,并返回文件中的最大字符

B.读取指定文件,并返回文件中字符的个数

C.写指定文件,并返回写入字符的个数

D.写指定文件,并返回文件中的最大字符

查看答案
如搜索结果不匹配,请 联系老师 获取答案
您可能会需要:
您的账号:,可能会需要:
您的账号:
发送账号密码至手机
发送
更多“int f(char fn[]) { fstream fil…”相关的问题

第1题

4. 下面是一个文件打不开的异常处理程序,分析程序并完...

4. 下面是一个文件打不开的异常处理程序,分析程序并完成相应问题。 (1)若磁盘中没有myfile.txt 文件,则输出结果如何? (2分) (2)说明特定模板函数的作用。(3分) #include<fstream> #include<iostream> using namespace std; int main() { ifstream source("myfile.txt"); //打开文件 char line[128]; char ss[] = "myfile.txt"; try { if (!source) throw ss; // 如果打开失败,抛出异常 } catch (char * s) { cout << "error opening the file " << s << endl; exit(1); } while (!source.eof()) //判断是否到文件末尾 { source.getline(line, sizeof(line)); cout << line << endl; } source.close(); return 0; }

点击查看答案

第2题

下面程序的功能是是读取文本文件in.txt中的全部内容,...

下面程序的功能是是读取文本文件in.txt中的全部内容,将文本存放到doc类的对象myDoc中。然后将myDoc中的字符字列反转,并输出到文件out.txt中。 文件int.txt的长度不大于1000字节。部分程序已给出,请将程序补充完成。 reverse( )函数实现将myDoc中的字符序列反转,并将反转后的序列在屏幕上输出。 #include <iostream> #include <fstream> #include <cstring> using namespace std; class doc { private: char *str; //文本字符串首地址 int length; //文本字符个数 public: doc(char *filename); void reverse(); //将字符序列反转 ~doc(); void writeToFile(char *filename); }; doc::doc(char *filename) { ifstream myFile(filename); int len=1001,tmp; str=new char[len]; length=0; while((tmp=myFile.get())!=EOF) { str[length++]=tmp; } str[length]='\0'; myFile.close(); } void doc::reverse() { .............. } doc::~doc() { delete [] str; } void doc::writeToFile(char *filename) { ofstream outFile(filename); outFile< <str; outfile.close(); } int main() { doc mydoc("in.txt"); mydoc.reverse(); mydoc.writetofile("out.txt"); return 0;>

点击查看答案

第3题

[图] 提示:补充横线上的代码,请使用英文半角输入,不要...

提示:补充横线上的代码,请使用英文半角输入,不要留空格及其他不可见字符。 #include <stdio.h> #include <stdlib.h> #define LL 80 #define COL 2 #define CSIZE LL/COL-9 #define PL 50 #define MARGIN 3 char buff[COL][PL][CSIZE]; int ln[COL][PL]; int col, row, p; void printout() { int k, i, lpos, col, d,j; char line[LL]; for (k = 0; k < MARGIN; k++) putchar('\n'); for (k = 0; k < PL; k++) { for (i = 0; i < LL - 1; i++) { line[i] = ' '; for (lpos = 0, col = 0; col < COL; lpos += CSIZE + 9, col++) { d = ln[col][k]; p = lpos + 4; while (d > 0) { line[p--] = d % 10 + '0'; d /= 10; } for (p = lpos + 7, j= 0; j < CSIZE;j++) line[p++] = buff[col][k][j]; } } line[p] = '\0'; puts(line); } for (k = 0; k < MARGIN; k++) putchar('\n'); } void nextline() { while (p < CSIZE) buff[col][row][p++] = ' '; if (++row >= PL) { if (++col >= COL) { printout(); col = 0; } row = 0; } p = 0; } void dprint(char* fname) { FILE* fp; int lin, c; if ((fp = fopen(fname, "r")) == NULL)exit(-1); lin = 0; p = 0; col = 0; c = getc(fp); while (c != EOF) { ln[col][row] = ++lin; while (c != '\n' && c != EOF) { if (p >= CSIZE) { nextline(); ln[col][row] = 0; } __________________; c = getc(fp); } nextline(); if (c != EOF)c = getc(fp); } while (col != 0 || row != 0) { ln[col][row] = 0; nextline(); } fclose(fp); } int main(int argc, char** argv) { int f; for (f = 1; f < argc; f++) dprint(argv[f]); return 0; }

点击查看答案

第4题

int add (int m,int n) { if (m > 100 || m < 0 || n > 100 || n < 0) return -1; return m+n; } 该程序期望输出两个100以内的正整数之和,和可以超过100。返回-1则表示输入参数不符合要求,不是程序期望的。 用边界值分析的方法测试该程序,如果要测试不期望的结果,要选择哪些测试数据()。

A、(1,1)

B、(0,99)

C、(99,0)

D、(1,99)

E、(1,100)

点击查看答案

第5题

以下程序输出的结果是 int a=23; int b=10; cout << a%b << endl;

A、3

B、4

C、5

D、6

E、2

F、1

点击查看答案

第6题

下列代码执行结果是 。 using namespace std; #include <iostream> int f(int Int) { if (Int==0) return 1; return (Int + f(Int-1)); } int main() { int inT=9; cout<< "result=" << f(inT) <<'\n'

B、result=37

C、result=46

D、编译错误

点击查看答案

第7题

假定in为ifstream类的对象,用in打开一个文件后,下面的代码用于读取文件内容: while(in) //读取文件内容 { char c=in.get(); if(in) cout< <c; }> A、确保循环能终止

B、是输入流操作中的语法要求

C、确保不重复输出最后读取的数据

D、if判别是多余的,可以不用

点击查看答案

第8题

已存在文件file.txt,其内容为sample1234ASDw,请写出程...

已存在文件file.txt,其内容为sample1234ASDw,请写出程序的运行结果 。 #include <stdio.h> #include <stdlib.h> int main( ) { FILE *fp; char ch; int count=0; fp = fopen( "file.txt", "r" ); if ( fp == 0 ) { printf( "file error\n" ); exit(1); } ch = fgetc(fp); while( !feof( fp ) ) { if ( ch >= 'a' && ch <= 'z') count++; ch="fgetc(fp);" } printf( "%d\n", count); fclose( fp ); return 0;>

点击查看答案
热门考试 全部 >
相关试卷 全部 >
账号:
你好,尊敬的上学吧用户
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
谢谢您的反馈

您认为本题答案有误,我们将认真、仔细核查,
如果您知道正确答案,欢迎您来纠错

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
上学吧
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反上学吧购买须知被冻结。您可在“上学吧”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
上学吧
点击打开微信