在C++编程思想一书中有一个程序我看不懂?请高手指点。
程序可以通过编译,可没有输出。应该怎样改才行。
#include <fstream.h>
#define D(a) T<<#a<<endl; a //这句是什么意思?我看不懂。特别是那个#a。
#include <conio.h>
ofstream T("format.out");
void main()
{
D(int i=47;)
D(float f=2300114.414159;)
char *s="Is there any more?";
D(T.setf(ios::unitbuf);)
D(T.setf(ios::stdio);)
D(T.setf(ios::showbase);)
D(T.setf(ios::uppercase);)
D(T.setf(ios::showpos);)
D(T<<i<<endl;) //Default to de
D(T.setf(ios::hex,ios::basefield);)
D(T<<i<<endl;)
D(T.unsetf(ios::uppercase);)
D(T.setf(ios::dec,ios::basefield);)
D(T.setf(ios::left,ios::adjustfield);)
D(T.fill('0');)
D(T<<"fill char: "<<T.fill()<<endl;)
D(T.width(10);)
T<<i<<endl;
D(T.setf(ios::right,ios::adjustfield);)
D(T.width(10);)
T<<i<<endl;
D(T.setf(ios::internal,ios::adjustfield);)
D(T.width(10);)
T<<i<<endl;
D(T<<i<<endl;) //without width(10)
D(T.unsetf(ios::showpos);)
D(T.setf(ios::showpoint);)
D(T<<"prec="<<T.precision()<<endl;)
D(T.setf(ios::scientific,ios::floatfield);)
D(T<<endl<<f<<endl;)
D(T.setf(ios::fixed,ios::floatfield);)
D(T<<f<<endl;)
D(T.setf(ios::fixed,ios::floatfield);)
D(T<<f<<endl;)
D(T.setf(0,ios::floatfield);) //automatic
D(T<<f<<endl;)
D(T.precision(20);)
D(T<<"prec ="<<T.precision()<<endl;)
D(T<<endl<<f<<endl;)
D(T.setf(ios::scientific,ios::floatfield);)
D(T<<endl<<f<<endl;)
D(T.setf(ios::fixed,ios::floatfield);)
D(T<<f<<endl;)
D(T.setf(0,ios::floatfield);)
D(T<<f<<endl;)
D(T.width(10);)
T<<s<<endl;
D(T.width(40);)
T<<s<<endl;
D(T.setf(ios::left,ios::adjustfield);)
D(T.width(40);)
T<<s<<endl;
D(T.unsetf(ios::showpoint);)
D(T.unsetf(ios::unitbuf);)
D(T.unsetf(ios::stdio);)
}
问题点数:50、回复次数:6Top
1 楼SCUM(人渣)回复于 2001-07-25 23:41:03 得分 30
解释性的输出信息而已Top
2 楼MSVCer(家宝)回复于 2001-07-26 02:34:31 得分 20
#define D(a) T<<#a<<endl; a
该句确实如SCUM(人渣)所言,是一个宏定义,但其中对'#"使用了一种特殊的用法
'#'号一般用在一个宏定义的开头处,以使预处理程序处理该句,若这个符号用在一个有参宏定义的中间,则其后的宏参数被做为一个常量字符串对待,'#'的这种用法只能是“有参”的宏定义,不能用在其它地方
此处用第一个宏输出D(int i=47;)做例,宏扩展后形式如下:
T<<"int i=47"<<endl; int i=47;
此宏即做了输出,又做了定义Top
3 楼z_sky()回复于 2001-07-26 09:31:32 得分 0
MSVCer(家宝)说的详细、准确,就是这样。 :-)Top
4 楼supershot(笨瓜)回复于 2001-07-26 09:53:23 得分 0
请问MSVCer(家宝)
偶是初学者,经常看到endl出现在程序尾部,请问是什么意思???Top
5 楼supershot(笨瓜)回复于 2001-07-26 10:48:27 得分 0
upTop
6 楼chenlee()回复于 2001-07-26 11:41:34 得分 0
end line,换行符Top




