需要包含頭文件
#include <conio.h>
在主對話框OnInitDialog()函數中添加
AllocConsole();
在需要顯示數據時(這裏使用的unicode數據集)
HANDLE hdlWrite = GetStdHandle(STD_OUTPUT_HANDLE); //這裏也可以使用STD_ERROR_HANDLE
DWORD dw;
TCHAR ch[256] = _T("你好");
WriteConsole(hdlWrite, ch, lstrlen(ch), &dw, NULL);
WriteConsole(hdlWrite, "\n", strlen("\n"), &dw, NULL);
double testDouble = 2017.0101;
TCHAR ch[256];
memset(ch, 0, 256);
_stprintf_s(ch, _T("%.4f"), testDouble);
WriteConsole(m_hdlWrite, ch, lstrlen(ch) , &m_dw, NULL);
WriteConsole(m_hdlWrite, "\n", strlen("\n"), &m_dw, NULL);
在程序結束時 如 OnClose() 中進行釋放
FreeConsole();