有如下程序: #include <iostream> using namespace std; class Base { public:
A.1B
B.1D
C.2B
D.2D
A.1B
B.1D
C.2B
D.2D
简要叙述下列程序代码,并判断如下程序的功能: #include <fstream> #include <iostream> using namespace std; int main(int argc, char* argv[]) { char c; fstream fio(argv[1], ios::in | ios::out); if (fio.fail()) //打开文件成功与否监控 { cerr << "Cannot open file:" << argv[1] << endl; return 1; } while((c=fio.get())!=EOF) //判断是否到达文件末尾 if (isupper(c)) { fio.seekg(-1, ios::cur); fio.put(tolower(c)); } fio.close(); return 0; }
有以下程序: #include<iostream.h> #include<iomanip.h> void main() { cout.fill('*'); cout.width(10); cout,<setiosflags(ios::left)<<123.45<<endl; } 程序执行后的输出结果是()
A.****123.45
B.**123.45**
C.123.45****
D.***123.45*
有以下程序:
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>
include<fstream>
using namespace std;
int main()
{
fstream file;
file.open("abc.txt", ios :: in);
if (!file )
{
cout<<"Can not open abc.txt"<<end1;
abort();
}
char buf[ 80 ];
int i = 0;
while (!file.eof())
{
file.getline(buf,80);
i++;
}
cout<<"Lines :"<<i<<end1;
file.close();
return 0;
}
程序实现的功能是【 】。
对于代码片段: #include <fstream> #include <iostream> using namespace std; int main(){ fstream binaryio; // Create stream object // Read array from the file binaryio.open("array.dat", ios::in | ios::binary); char result[10] = {'\0'}; binaryio.read(reinterpret_cast <char *> (result), 20); cout << result; return 0; } 其中array.dat文件中存放的内容以字节序列表示,各字节的值为 0x30, 0x31, ..., 0x60 执行之后可能出现的状况有:
A、屏幕上没有输出,程序结束,未报告错误
B、屏幕上输出了10个以上字符,程序结束,未报告错误
C、屏幕上输出了10个以上字符,程序出错
D、屏幕上输出了9个字符,然后程序报错
屏幕,并且将文件按照以上方式分割,存于文件out1.txt和out2.txt中。
其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。
(1)从输入文件中获得一个字符,并判断是否到文件结
尾,如果到文件结尾,则退出循环。请在注释1后添加适当的语句。
(2)把获得的输入文件的内容存储到bur中,并且用len
记录下文件的长度。请在注释2后添加适当的语句。
(3)将输入文件的后一半内容存储在第二个文件中,请
在注释3后添加适当的语句。
(4)使用文件流对象打开输入文件in.txt,请在注释4
后添加适当的语句。
注意:增加代码或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。
试题程序:
include<iostream.h>
include<fstream.h>
include<stdlib.h)
classTC
{
public:
TC(char*fileName)
{
len=0;
fstreaminfile;
infile.open(fileName,ios::in);
charch;
//********1********
while
{
cout<<ch;
//********2********
}
infile.close;
}
voidsplit
{
fstreamoutfilel;
fstreamoutfile2;
outfile1.open("out1.txt",ios::out);
outfile2.open("out2.txt",ios::out);
inti=0:
for(i=0;i<len/2;i++)
{
outfilel<<buf[i];
}
do
{
//********3********
}
while(i!=len);
outfilel.close;
outfile2.close;
}
prwate:
intlen;
charbuf[1024];
};
voidmain
{
//********4********
TCobj;
obj.split;
return;
}
以下程序的执行结果是_______。
include<iostream.h>
include<fstream.h>
include<stdlib.h>
void main()
{
char ch:
fstream file:
file.open("abc.dat",ios::out1ios::inlios::binary);
if(! file)
{
cout<<“abc.dat文件不能打开”<<endl:
abort
假设文本文件letters.txt中已经存有“1234567890”十个字符,则下列程序的运行结果是 。 #include <fstream.h> #include <stdlib.h> void main(void) { fstream file("nums.txt",ios::in); char ch; if (!file) exit(0); file.seekg (1L, ios::beg); file.get(ch); cout << ch << endl; file.seekg (-5L, ios::end); file.get(ch); cout << ch << endl; file.seekg (-2L, ios::cur); file.get(ch); cout << ch << endl; file.close(); }
B.***123456***
C.***123456
D.123456
文本文件letters.txt中已经存有“abcdefg”七个字符,则下列程序的运行结果是 。 #include <fstream.h> #include <stdlib.h> void main(void) { fstream file("letters.txt",ios::in); char ch; if (!file) exit(0); file.seekg (2L, ios::beg); file.get(ch); cout << ch ; file.seekg (-3L, ios::end); file.get(ch); cout << ch ; file.seekg (1L, ios::cur); file.get(ch); cout << ch << endl; file.close(); }
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!