计算机二级

有以下程序:includeincludevoid main(){cout.fill('*');cout.width(10有以下程序: #include<iostream.h> #include<iomanip.h> void main() { cout.fill('*'); cout.width(10); cout,<setiosflags(ios::left)<<123.45<<endl; } 程序执行后的输出结果是( )A.****123.45B.**123.45**C.123.45****D.***

题目
有以下程序:includeincludevoid main(){cout.fill('*');cout.width(10

有以下程序: #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*

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下列程序的执行结果为______。include void main() { cout.fill(‘*’); tout.width(10

下列程序的执行结果为______。

include<iostream.h>

void main()

{

cout.fill(‘*’);

tout.width(10);

cout<<“hello”<<endl;

)


正确答案:* * * * *hello。
* * * * *hello。 解析: 本题考查的是C++语言的流输出操作,eout中包括的函数fill()和width()分别实现填充和设定显示长度的功能。

第2题:

有如下程序:include includeusing namespace std;int main(){cout.fill('*

有如下程序:#include <iostream>#include<iomanip>using namespace std;int main(){ cout.fill('*'); cout.width(6); cout.fill('#'); cout<<123<<end1; return 0;}执行后的输出结果是( )。

A.###123

B.123###

C.***123

D.123***


正确答案:A

第3题:

有如下程序: include include using namespace std; int main() {cout.f

有如下程序: #include <iostream> #include <iomanip> using namespace std; int main() { cout.fill('*'); cout.width(6); cout.fill('#'); cout<<123<<end1; return 0; } 执行生的输出结果是( )。

A. ###123

B.123###

C. ***123

D.123***


正确答案:A

第4题:

有如下程序:include using namespacestd;int main(){cout.fill('*');cout.width(6);c

有如下程序: #include <iostream> using namespace std; int main(){ cout.fill('*'); cout.width(6); cout.fill('#'); cout<<123<<end1; return 0;} 执行后的输出结果是

A.###123

B.123###

C.***123

D.123***


正确答案:A
解析:本题考核I/O的格式化输出。语句“cout.fill('*');”表示填充字符为‘*’,并且一直有效,直到再次设置填充字符为止。语句 “cout.width(6);”用来设置输入输出宽度,当实际数据宽度小于指定的宽度时,多余的位置用填充字符填满;当实际数据的宽度大于设置的宽度时,仍按实际的宽度输出。语句“cout.fill('#');”表示将填充字符改为‘#’(即把之前设置的‘#’改为‘#’),由于数据“123”的实际宽度小于6,由于输出的初始状态为在输出宽度内右对齐,所以前面将会有3个填充字符‘#’。

第5题:

有如下程序:includeusing namespace std;int main(){ cout.fill('*'); cout.width (6

有如下程序: #include<iostream> using namespace std; int main() { cout.fill('*'); cout.width (6); cout.fill('#'); cout<<123<<end1; return 0; }执行后的输出结果是______ 。

A.###123

B.123###

C.***123

D.123***


正确答案:A
解析:根据定义,开始设置的coutfill.(‘*’),被后面的cout.fill(‘#’)替代,所以cout的输出结果是###123。

第6题:

有如下程序:includeusing namespace std;int main(){cout.fill('*');cout.width(6);c

有如下程序: #include<iostream> using namespace std; int main() { cout.fill('*'); cout.width(6); cout.fill('#'); cout<<888<<end1; return 0; } 的执行结果是( )。

A.###888

B.888###

C. ***888

D.888***


正确答案:A
解析:C++在流操作中,利用cout对象的width属性设置输出字符的宽度,用fill函数来设置需要填充的字符。题目程序中,首先设置填充字符为*,输出宽度为6,但存输出前又设置了填充字符为#。所以在输出时,其填充字符为#,由于888不足6个字符,所以在前面以三个“#”来填充。

第7题:

下列程序的执行结果是______。 include include using namespace std; vo

下列程序的执行结果是______。

include<iostream.h>

include<iomanip.h>

using namespace std;

voidmain()

{

cout<<setfill('x')<<setw(10);

cout<<"Hello"<<end1;

}


正确答案:xxxxxHello
xxxxxHello 解析:此题考查的是I/O的格式化输出。Setfill('x')表示填充字符为V,并且一直有效;setw(10)表示将输入输出的宽度设置为10,宽度设置的效果只对以此次输入或输出有效,在完成一个数据的输入或输出后,宽度自动恢复为0;题目中字符串“Hello”的宽度不够10,所以其前面将有5个填充符V。

第8题:

下面程序的执行结果是______。 include include using namespace std; vo

下面程序的执行结果是______。

include<iostream.h>

include<iomanip.h>

using namespace std;

void main()

{

cout<<setfill('x')<<setw(10);

cout<<"Hello"<<endl;

}


正确答案:xxxxxHello
xxxxxHello 解析:本题考核I/O的格式化输出。setfill('x')表示填充字符为'x',并且一直有效,直到再次设置填充字符为止。setw(10)表示将输入输出宽度设置为10,当实际数据宽度小于指定的宽度时,多余的位置用填充字符填满;当实际数据的宽度大于设置的宽度时,仍按实际的宽度输出。宽度设置的效果只对一次输入或输出有效,在完成一个数据的输入或输出后,宽度设置自动恢复为0(表示按数据实际宽度输入输出)。题中字符串“Hello”的宽度不够10,所以其前面将有5个填充符 'x'。

第9题:

下列程序的执行结果为【15】。

#include(iostream. h>

void main()

{

Cout.fill(’*’);

cout. width(10);

cout <<”hello”<

}


正确答案:
*****hello