我想知道这个程序的意思

guowl2008 2009-03-08 11:21:49
#include<iostream.h>
#include<iomanip.h>
void main( )
{ int a=123;
int &ra=a;
int *pa=&a;
cout<<setw (5)<<dec<<a<<setw (5)<<oct<<ra<<setw (5)<<hex<<*pa<<endl;
} 谁能告诉我这是个什么程序 setw (5)是什么意思啊 dec,setw是什么意思啊
...全文
189 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzx716 2009-03-09
  • 打赏
  • 举报
回复
书上都没有,这里学到了
bbb332 2009-03-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 preserve 的回复:]
w是width宽度的缩写
楼上正解
[/Quote]...
guowl2008 2009-03-09
  • 打赏
  • 举报
回复
我错了 我想错了 对不起麻烦大家了
lzy340623339 2009-03-09
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 guowl2008 的回复:]
那十进制怎么是123八进制是173的啊 大家可以教教我吗 我太笨了 麻烦一下哦
[/Quote]
进制转换,八进制的173转换为十进制1*8^2+7*8+3=123
lz还是应该先从基础打起
guowl2008 2009-03-09
  • 打赏
  • 举报
回复
我还是不太懂啊 麻烦你教我好吗
luyaowei 2009-03-08
  • 打赏
  • 举报
回复
5楼说得很清楚了。。。
guowl2008 2009-03-08
  • 打赏
  • 举报
回复
那十进制怎么是123八进制是173的啊 大家可以教教我吗 我太笨了 麻烦一下哦
guowl2008 2009-03-08
  • 打赏
  • 举报
回复
nb
grellen 2009-03-08
  • 打赏
  • 举报
回复
楼上都说了
  • 打赏
  • 举报
回复
setw ,配合cout输.
http://www.kuqin.com/cpplib/iostream/manipulators/setw.html
yangch_nhcmo 2009-03-08
  • 打赏
  • 举报
回复
setw()函数用来设置输出字符位宽;

dec read/write integral values using decimal base format.
hex read/write integral values using hexadecimal base format.
oct read/write integral values using octal base format.

Example

#include <iostream>
using namespace std;

int main () {
int n;
n=70;
cout << dec << n << endl;
cout << hex << n << endl;
cout << oct << n << endl;
return 0;
}

The execution of this example displays something similar to:

70
46
106
yujunfei_xy 2009-03-08
  • 打赏
  • 举报
回复
setw(5)是控制输出宽度为5;
dec表示以十进制输出,即输出123
oct表示以八进制输出,即输出173
hex表示以十六进制输出,即输出7B
mengde007 2009-03-08
  • 打赏
  • 举报
回复
设置字符输出宽度为5,dec为十进制,hex为十六进制,oct为八进制。
Sco_field 2009-03-08
  • 打赏
  • 举报
回复

#include <iostream.h>
#include <iomanip.h>
void main( )
{
int a=123;
int &ra=a; // 引用,ra=123
int *pa=&a; // 指针,*pa=123
cout <<setw (5) <<dec <<a // setw设置输出字符的位宽,这里是5.
// 如果显示数据所需的宽度比设置的域宽小,空位用填充字符填充。
// 如果显示数据所需的宽度比设置的域宽大,显示数据并不会被截断,系统会输出所有位。
// dec:10进制输出
<<setw (5) <<oct <<ra // 8进制输出
<<setw (5) <<hex <<*pa // 16进制输出
<<endl;
}


lz结贴吧,呵呵

[Quote=引用楼主 guowl2008 的帖子:]
#include <iostream.h>
#include <iomanip.h>
void main( )
{ int a=123;
int &ra=a;
int *pa=&a;
cout < <setw (5) < <dec < <a < <setw (5) < <oct < <ra < <setw (5) < <hex < <*pa < <endl;
} 谁能告诉我这是个什么程序 setw (5)是什么意思啊 dec,setw是什么意思啊
[/Quote]
preserve 2009-03-08
  • 打赏
  • 举报
回复
w是width宽度的缩写
楼上正解
lingyin55 2009-03-08
  • 打赏
  • 举报
回复
setw

Specifies the width of the display field.


T6 setw(
streamsize _Wide
);


Parameters
_Wide
The width of the display field.

Return Value
The manipulator returns an object that, when extracted from or inserted into the stream str, calls str.width(_Wide), then returns str.

dec

Specifies that integer variables appear in base 10 notation.


ios_base& dec(
ios_base& _Str
);


Parameters
_Str
A reference to an object of type ios_base, or to a type that inherits from ios_base.

Return Value
A reference to the object from which _Str is derived.

这些东西msdn上都有。


chin_chen 2009-03-08
  • 打赏
  • 举报
回复
dec十进制输出
chin_chen 2009-03-08
  • 打赏
  • 举报
回复
那个是输出控制符!宽度为5,

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧