最奇怪的事情正在发生。在下面的程序中,我打印出一行。照原样,程序输出以下内容:
-----FOCUS-----:0x22fc80:
但是,如果我在 cout 之后注释掉 7 个语句中的任何一个,我会得到以下信息:
-----FOCUS-----:0:
我已经包含了 tchar.h、windows.h、iostream 和 Psapi.h。我正在使用 MinGW-64,编译命令是:
"C:\MinGW64\bin\g++.exe" -o MyProgram.exe MyProgram.cpp -lpsapi
该程序是:
int main()
{
HWND focusThreadWnd = GetForegroundWindow();
DWORD focusThreadID = GetWindowThreadProcessId(focusThreadWnd,0);
GUITHREADINFO focusThreadInfo;
GetGUIThreadInfo(focusThreadID, &focusThreadInfo);
HWND focus = focusThreadInfo.hwndFocus;
cout << "-----FOCUS-----:" << focus << ":" << endl;
HWND k1Focus = focusThreadWnd;
HWND k2Focus = focusThreadWnd;
HWND k3Focus = focusThreadWnd;
HWND k4Focus = focusThreadWnd;
HWND k5Focus = focusThreadWnd;
HWND k6Focus = focusThreadWnd;
HWND k7Focus = focusThreadWnd;
}
所以我的问题是, cout 之后的命令如何影响输出?而且,为什么这七个命令中的存储会改变输出?而且,7有什么特别之处?