“while”应改为“while(infile.get(ch))”。 (2)应添加“bur[len++]=ch;bur[len]=ch;len++;”。 (3)应添加“outfile2bur[i++];”或“outfile2buf[i];i++;”。 (4)“TCobj;”应改为“TCobi("in.txt");”。 【解析】本题考查了文件流的使用。根据题意,第1处要获得一个字符,并判断是否到文件结尾,所以应使用get函数;第2处应将ch存入buf数组,同时让len增1;第3处将buf中的字节输出给outfile2,注意同时让i增1,否则while循环将进入死循环;第4处TC只确一个带char*参数的构造函数,所以创建对象时必须使用构造参数,根据题意这个参数应该是“"in.txt"”。

“while”应改为“while(infile.get(ch))”。 (2)应添加“bur[len++]=ch;bur[len]=ch;len++;”。 (3)应添加“outfile2<<bur[i++];”或“outfile2<<buf[i];i++;”。 (4)“TCobj;”应改为“TCobi("in.txt");”。 【解析】本题考查了文件流的使用。根据题意,第1处要获得一个字符,并判断是否到文件结尾,所以应使用get函数;第2处应将ch存入buf数组,同时让len增1;第3处将buf中的字节输出给outfile2,注意同时让i增1,否则while循环将进入死循环;第4处TC只确一个带char*参数的构造函数,所以创建对象时必须使用构造参数,根据题意这个参数应该是“"in.txt"”。


相关考题:

要求通过 while 循环不断读入字符 , 当读入字母 N 时结束循环 。 若变量已正确定义 , 以下正确的程序段是A)while((ch=getchar())!='N') printf(" % c",ch);B)while(ch=getchar()!='N') printf(" % c",ch);C)while(ch=getchar()=='N') printf(" % c",ch);D)while((ch=getchar())=='N') printf(" % c",ch);

要求通过while循环不断读入字符,当读入字母N时结束循环。若变量已正确定义,下列正确的程序段是( )A.while((ch=getchar ())!='N')printf("%c",ch);B.while(ch=getchar()!='N') printf("%c",ch);C.while(ch=getchar()=='N') printf("%c",ch);D.while((ch=getchar()) =='N')printf('%c',ch);

若变量已正确定义,下列正确的程序段是( )。A.while(ch=getchar()=='\N')putchar(ch);B.while((ch=getchar())=='\n')putchar(ch);C.while((ch=getchar())!='\N')putchar(ch);D.while((ch=getchar())!='\n')putchar(ch);

要求通过while循环不断读入字符,当读入字母N时结束循环。若变量已正确定义,以下正确的程序段是( )。A.while((ch=getchar())!='N')printf("%c",ch);B.while(ch=getchar()!='N')printf("%c",ch);C.while(ch=getchar()=='N')printf("%c",ch);D.while((ch=getchar())=='N')printf("%c",ch):

若变量已正确定义,下列正确的程序段是( )。A.while(ch=getchar()=='\NN')putchar(ch);B.while((ch=getchar())=='\n')putchar(ch);C.while((ch=getchar())!='\N')putchar(ch);D.while((ch=getchar())!='\n')putchar(ch);

若变量已正确定义,下列正确的程序段是( )。A.while(ch=getchar()=='\N')putchar(ch);B.while((ch=getchar())=='\n')putchar(ch);C.while((ch=getchar())!='\N')putchar(ch);D.while((ch=getchar())!='\n')putchar(ch);

要求通过while循环不断读入字符,当读入字母'N'时结束循环。若变量已正确定义,以下正确的程序段是( )。A.while(( ch = getchar( )) ! ='N') printf(" %c",ch);B.while(ch = getehar() ! ='N')printf("%c",ch);C.while (ch = getehar() = = 'N')printf( "%c", ch);D.while ((ch = getchar( )) == 'N')printf("%c", ch );

要求通过while循环不断读入字符,当读入字母N时结束循环。若变量已正确定义,以下正确的程序段是()A.while(ch=getchar() ='N') printf("%c ",ch);B.while((ch=getchar())!='N') printf("%c ",ch);C.while(ch=getchar()=='N') printf("%c ",ch);D.while((ch=getchar())=='N') printf("%c ",ch);

要求通过while循环不断读入字符,当读入字母N时结束循环。若变量已正确定义,以下正确的程序段是()。A.while((ch=getchar())!='N' printf(“%c”,ch) ;B.while(ch=getchar()!='N' printf(“%c”,ch) ;C.while(ch=getchar())=='N' printf(“%c”,ch);D.while((ch=getchar())=='N' printf(“%c”,ch);