有以下程序:
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;
}
此程序实现的功能是【 】。
第1题:
有以下程序:
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;
}
程序实现的功能是【 】。
第2题:
写出下列程序的运行结果【 】。
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();
}
第3题:
阅读以下程序,给出运行结果 #include <iostream> #include <cstring> using namespace std; int main() { string str="I love China!"; cout << str; return 0; }
第4题:
有以下程序: #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.#
第5题:
有以下程序: #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