看板 C_and_CPP 關於我們 聯絡資訊
我是用Visual C++開發的 主要是在DWORD這個型態出問題 利用sprintf_s將DWORD型態資料寫入字串 印出時會出現亂碼 程式碼節錄如下 麻煩知道問題在哪的高手解惑 感謝 //--------------------------------- DWORD dwTime; dwTime = GetTickCount(); DWORD hr, min, second, temp = dwTime / 1000; char str[1000]; hr = temp / 3600; temp %= 3600; min = temp / 60; temp %= 60; second = temp; if(hr) sprintf_s(str,1000,"Costed time: %u hr %u min %u sec.", hr, min, second ); else if( min ) sprintf_s(str, 1000, "Costed time : %u min %u sec.", min, second ); else if( second ) sprintf_s(str, 1000, "Costed time : %u sec.", second ); else sprintf_s(str, 1000, "Costed time : %u ms.", dwTime ); MessageBox(NULL, (LPCWSTR)str, TEXT("執行花費時間"), MB_OK); -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.57.244.30
VictorTom:改用MessageBoxA()試試. 11/19 17:47
VictorTom:這種問題建議試著從確認str印的對不對, 與MessageBox印 11/19 17:48
VictorTom:的對不對來釐清; 個人覺得VC做step by step debug與 11/19 17:48
VictorTom:watch已經是相當方便的IDE tool了:) 11/19 17:49
VictorTom:這個問題大概跟char, wchar, tchar之間的問題有關:) 11/19 17:52
ledia:看到 LPCWSTR 的 W, 大概就是這類的問題了 11/19 18:04
VictorTom:跟樓上l大一樣, 小弟也是看到這個就猜了XD 11/19 18:31
snow1223:改用MessageBoxA就OK了 謝謝V大^^ 11/20 11:07
VictorTom:建議有空了解一下小弟5F推的東西, 只要你還寫跟WinAPI與 11/20 11:08
VictorTom:Text處理/display有關的程式, 八成都可能會再遇到:) 11/20 11:09