是否可以在不指定变量类型的情况下将变量值打印到 Debug?
Is possible to print variables values to Debug without specifying their types?
我正在将变量的值打印到 DebugView。
除了手动指定 %
VarTYPE
之外,还有任何 'easier' 方法来打印它们的值
目前这样做:
WCHAR wsText[255] = L"";
wsprintf(wsText, L"dwExStyle: %??? lpClassName: %??? lpWindowName: %??? ...", dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, ...);
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
它不一定需要是 wsprintf
,能够在不需要手动指定每个参数类型的情况下打印它会有所帮助!
是的,使用字符串流,它们也比 wsprintf 更安全(缓冲区溢出)。对于未知类型,您可以重载运算符 <<.
#include <Windows.h>
#include <string>
#include <sstream>
int main()
{
DWORD dwExStyle{ 0 };
std::wstringstream wss;
wss << L"dwExtStyle : " << dwExStyle << ", lpClassName: "; // and more....
OutputDebugString(wss.str().c_str());
}
std::ostream& operator<<(std::ostream& os, const your_type& value)
{
os << value.member; // or something
return os;
}
我正在将变量的值打印到 DebugView。
除了手动指定 %
VarTYPE
目前这样做:
WCHAR wsText[255] = L"";
wsprintf(wsText, L"dwExStyle: %??? lpClassName: %??? lpWindowName: %??? ...", dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, ...);
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
它不一定需要是 wsprintf
,能够在不需要手动指定每个参数类型的情况下打印它会有所帮助!
是的,使用字符串流,它们也比 wsprintf 更安全(缓冲区溢出)。对于未知类型,您可以重载运算符 <<.
#include <Windows.h>
#include <string>
#include <sstream>
int main()
{
DWORD dwExStyle{ 0 };
std::wstringstream wss;
wss << L"dwExtStyle : " << dwExStyle << ", lpClassName: "; // and more....
OutputDebugString(wss.str().c_str());
}
std::ostream& operator<<(std::ostream& os, const your_type& value)
{
os << value.member; // or something
return os;
}