我对VC ++有疑问 如果你在VC ++中编译这段代码:
#include "stdafx.h"
#include <stdlib.h>
//#include <stdio.h>
#include <iostream>
#include <Windows.h>
TCHAR lpBuffer[MAX_PATH];
int _tmain(int argc, _TCHAR* argv[])
{
DWORD dwBufferLength = 0;
if(!(dwBufferLength = GetWindowsDirectory(lpBuffer, MAX_PATH)))
std::cout << "Last error : "<< GetLastError() << std::endl;
else{
std::cout << lpBuffer << std::endl;
/*for(DWORD i = 0; i < dwBufferLength; i++)
printf("%c", lpBuffer);*/
std::cout << std::endl;
}
system("PAUSE");
return 0;
}
我只看到“C”,如果我用g ++编译它,我会看到“C:\ Windows”有什么问题? 我确定我应该删除第一行“#include”stdafx“”在g ++下:)
并将“_tmain”更改为“main”^ __ ^
答案 0 :(得分:1)
更正代码后:
#include <iostream>
#include <Windows.h>
int main() {
char lpBuffer[MAX_PATH];
DWORD dwBufferLength = 0;
if(!(dwBufferLength = GetWindowsDirectory(lpBuffer, MAX_PATH)))
std::cout << "Last error : "<< GetLastError() << std::endl;
else
std::cout << lpBuffer << "\n";
return 0;
}
我用VC ++(2012)和gcc 4.7.2(MinGW)得到相同的结果(“C:\ windows”)。