define语句问题,下面这句话放在switch语句之前,是什么意思?(我指“#”号和“_T”):
#define EXCEPTION( x ) case EXCEPTION_##x: return _T(#x);switch语句是这样的:
switch ( dwCode )
{
    EXCEPTION( ACCESS_VIOLATION )
    。
}
printf语句问题,在TCHAR.H中有这样的定义“#define _tprintf    printf”,是不是指_tprintf等价于printf呢?下面这段代码能够将printf语句的内容写入文件吗?
SetFilePointer( m_hReportFile, 0, 0, FILE_END );
_tprintf( _T("//=====================================================\n") );
CloseHandle( m_hReportFile );
m_hReportFile = 0;

解决方案 »

  1.   

    1.
    宏定义中的##的的意思是将前后两部分连接成一个整体
    而一个#表示在后面的东西两边加上双引号,即将其变成一个字符串
    当遇到
    EXCEPTION(ACCESS_VIOLATION)

    编译器会将其扩展成
    case EXCEPTION_ACCESS_VIOLATION: return _T("ACCESS_VIOLATION");2.
    _tprintf的定义其实是这样的:
    #ifdef _UNICODE
    #define _tprintf wprintf
    #else
    #define _tprintf printf
    #endif
    这样定义的目的是当你使用_tprintf的时候能够使你能够在不修改源程序的情况下,编译成Unicode版和non-Unicode版
      

  2.   


    Earthdog(没有女朋友,郁闷!) 
    说的已经非常详细了,我帮他up
      

  3.   

    1,
    This example illustrates use of both the stringizing and token-pasting operators in specifying program output:#define paster( n ) printf( "token" #n " = %d", token##n )
    int token9 = 9;
    If a macro is called with a numeric argument likepaster( 9 );
    the macro yieldsprintf( "token" "9" " = %d", token9 );
    which becomesprintf( "token9 = %d", token9 );
    #define stringer( x ) printf( #x "\n" )int main()
    {
        stringer( In quotes in the printf function call\n ); 
        stringer( "In quotes when printed to the screen"\n );   
        stringer( "This: \"  prints an escaped double quote" );
    }
    Such invocations would be expanded during preprocessing, producing the following code:
    int main()
    {
       printf( "In quotes in the printf function call\n" "\n" );
       printf( "\"In quotes when printed to the screen\"\n" "\n" );
       printf( "\"This: \\\" prints an escaped double quote\"" "\n" );
    }
      

  4.   

    补充一下,_T的定义如下:
    #ifdef _UNICODE
    #define _T(x)  L##x
    #else
    #define _T(x) x
    #endif也是为了能够使程序可以自由的在unicode和非unicode版本之间编译的时候使用
      

  5.   

    那么这个_tprintf能被重写吗?
      

  6.   

    那只是一个宏定义,宏定义是可以重新定义的,不过最好不要重新定义#ifdef _tprintf
    #undef _tprintf
    #endif然后在定义成你需要的东西就可以了