TRACE 巨集

更新:2010 年 10 月

這個主題適用於:

版本

Visual Basic

C#

F#

C++

Web Developer

Express

標題不適用於 標題不適用於 標題不適用於

僅適用原生

標題不適用於

Pro、Premium 和 Ultimate

標題不適用於 標題不適用於 標題不適用於

僅適用原生

標題不適用於

若要在偵錯工具輸出視窗裡顯示程式的訊息,您可以使用 ATLTRACE 巨集或 MFC TRACE 巨集。 像判斷提示一樣,追蹤巨集只有在程式的偵錯版本才會啟動而且在發行版本編譯時會消失。

下列範例顯示一些您可以使用 TRACE 巨集的方式。 就像 printf 一樣,TRACE 巨集可以處理許多引數。

int x = 1;
int y = 16;
float z = 32.0;
TRACE( "This is a TRACE statement\n" );

TRACE( "The value of x is %d\n", x );

TRACE( "x = %d and y = %d\n", x, y );

TRACE( "x = %d and y = %x and z = %f\n", x, y, z );

TRACE 巨集會適當處理 char* 和 wchar_t* 這兩種參數。 下列範例示範搭配不同類型的字串參數來使用 TRACE 巨集。

TRACE( "This is a test of the TRACE macro that uses an ANSI string: %s %d\n", "The number is:", 2);

TRACE( L"This is a test of the TRACE macro that uses a UNICODE string: %s %d\n", L"The number is:", 2);

TRACE( _T("This is a test of the TRACE macro that uses a TCHAR string: %s %d\n"), _T("The number is:"), 2);

如需 TRACE 巨集的詳細資訊,請參閱診斷服務

請參閱

其他資源

MFC 偵錯技術

變更記錄

日期

記錄

原因

2010 年 10 月

釐清 UNICODE 支援/多位元組支援。

客戶回函。