有如下程序: #inc1ude<iostream> #inc1ude<iomanip> using namespace std; int main(){ cout<<setfill(’#’)<<setw(4)<<"OK"<<

admin2016-11-23  24

问题 有如下程序:
    #inc1ude<iostream>
    #inc1ude<iomanip>
  using namespace std;
  int main(){
    cout<<setfill(’#’)<<setw(4)<<"OK"<<123<<endl;
    retum 0;
    }
运行这个程序的输出结果是(     )。

选项 A、##OK123
B、##OK#123
C、OK##123
D、OK##123#

答案A

解析 setfill是设置填充字符,setw设置输出的宽度,它们的作用表现在紧接着输出的字符串上。这个宽度是填充后的宽度。所以cout<<setfill(’#’)<<setw,(4)<<"OK"<<123中,setfill和setw只作用在"OK",表示在"OK"前面填充2个≠≠撑。
转载请注明原文地址:https://kaotiyun.com/show/lzAp777K
0

最新回复(0)