在CWinApp的InitInstance中对话框的DoModal之前加入
void MyUseConsole(void)
{
AllocConsole(); // 开辟控制台
SetConsoleTitle(_T(""));//设置控制台窗口标题
freopen("CONOUT$", "w", stdout);// 重定向输出
freopen("CONIN$", "r+t", stdin);// 申请读
}
在CWinApp的ExitInstance中加入
FreeConsole();//释放控制台
直接printf或cout
CCHESSPLAY()->OutStatus(std::cout);
void CChessPlay::OutStatus(ostream& os)
{
os<<"chessboard:\n";
for (size_t i =3;i <= 12;++i)
{
for (size_t j=3;j <= 11;++j)
{
os<<Global::g_chessmanName[Global::g_chessboard[i][j]]<<" ";
}
os<<"\n";
}
os<<"\n";
os<<"chess man:\n";
for (size_t i = 16 ;i < Global::g_chessman.size(); ++i)
{
os << std::setw(2) << Global::g_chessmanName[i]<< " ";
}
os<<"\n";
for (size_t i = 16;i < Global::g_chessman.size(); ++i)
{
bool alive = Global::g_chessman[i]->Alive() ? true : false;
os<<std::setw(2)<<alive<<" ";
}
os<<"\n";
os << "evaluate:" << m_evaluate << "\n" << endl;
}