有以下程序: include include include intmain() {fstreamfil有以下程序:include <iostream.h>include <fstream.h>include <stdlib.h>int main(){fstream filel,file2;char line[100];filel.open("source.txt",ios::in);if(!file1){cout<<"Can't open file source.txt!"<<end1;abort();

题目
有以下程序: include include include intmain() {fstreamfil

有以下程序:

include <iostream.h>

include <fstream.h>

include <stdlib.h>

int main()

{

fstream filel,file2;

char line[100];

filel.open("source.txt",ios::in);

if(!file1)

{

cout<<"Can't open file source.txt!"<<end1;

abort();

}

file2.open("dest.txt",ios::out);

if(!file2)

{

cout<<"Can't open file dest.txt!"<<end1;

abort();

}

while(!file1.eof())

{

filel.getline(1ine,100);

file2<<line;

file2<<end1;

}

filel.close();

file2.close();

return 0;

}

此程序实现的功能是【 】。


相似考题
更多“有以下程序: include<iostream.h> include<fstream.h> include<stdlib.h> intmain() {fstreamfil ”相关问题
  • 第1题:

    有以下程序: include include using namespace std; int main () {char ch[]

    有以下程序:

    include <fstream>

    include <string>

    using namespace std;

    int main ()

    {

    char ch[] = "The end";

    ofstream outstr( "d:\\put.txt", ios_base: :app);

    for (int i = 0; i < strlen( ch ); i++ )

    outstr.put(ch[i]);

    outstr.close();

    return 0;

    }

    程序实现的功能是【 】。


    正确答案:在文件put.txt的尾部追加写入一串字符
    在文件put.txt的尾部追加写入一串字符 解析:解本题的关键是要了解文件打开模式常量ios_base::app的含义。常量ios base::app表示为添加数据而打开文件(总是在文件尾部写),因此上述程序实现的功能就是在文件尾部写入数组ch中字符串。

  • 第2题:

    写出下列程序的运行结果【】。include .include include void ma

    写出下列程序的运行结果【 】。

    include <iostream.h>.

    include <fstream.h>

    include <stdlib.h>

    void main()

    {

    fstream outfile, infile;

    outfile.open("data.clat", ios:: out);

    if(!outfile)

    {

    cout<<"Can't open the file."<<end1;

    abort();

    }

    outfile<<" 1234567890"<<end1;

    outfile<<"aaaaaaaaa"<<end1;

    outfile<<"**********"<<end1;

    outfile.close();

    infile.open("data. dat ", ios:: in);

    if(!infile)

    {

    cout<<"Can't open the file."<<end1;

    abort();

    }

    char line[80];

    int I=0;

    while(!infile. eof())

    {

    I++;

    infile.getline(line, sizeof(line));

    cout<<I<<":"<<line<<end1;

    }

    infile.close();

    }


    正确答案:1: 1234567890 2:aaaaaaaaa 3:********** 4:
    1: 1234567890 2:aaaaaaaaa 3:********** 4:

  • 第3题:

    阅读以下程序,给出运行结果 #include <iostream> #include <cstring> using namespace std; int main() { string str="I love China!"; cout << str; return 0; }


    emoclew emoclew

  • 第4题:

    有以下程序:include include using namespace std;int main ( ){ ofstream

    有以下程序: #include <iostream> #include <fstream> using namespace std; int main ( ) { ofstream ofile; char ch; ofile.open ("abc.txt"); cin>>ch; while (ch!='#' ) { cin>>ch; ofile.put(ch);

    A.程序编译时出错

    B.abc#

    C.abc

    D.#


    正确答案:C
    解析:本题程序的功能是将从键盘终端输入的内容存储到指定的文件中。

  • 第5题:

    有以下程序:includeincludeusxng namespace std;int main(){ char p[] = "a

    有以下程序: #include <iostream> #include <string> usxng namespace std; int main() { char p[] = "abcdefgh"; cout<<strlen(strcpy(p,"12345"))<<end1; return 0; } 执行后输出的结果是( )。

    A.8

    B.12

    C.5

    D.7


    正确答案:C
    解析:本题考查对字符串函数的熟悉程度。本题主要考查strlen和strcpy两个函数,先来了解这两个函数。①函数strcpy()的函数原型为:char*strcpy(char*strDest,constchar*strSrC);其功能是复制strSrc所有字符到strDest,并返回strDest。②函数strlen()的函数原型为:size_tstrlen(constchar*string);,其功能是返回string的长度,不包括结束字符'\0'。在了解函数的原型和功能后,再分析本程序。程序首先定义了字符数组p,并赋初值"abcdefg",然后将字符串"12345"复制到数组p中,此时数组中元素变为字符串"12345",然后调用函数strlen求出数组p中的字符数为5(不包括结束标志符'\0')。