0

如果您在 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”有什么问题?当然我应该删除g ++下的第一行“#include“stdafx”:)

并将“_tmain”更改为“main”^__^

4

1 回答 1

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”)。

于 2013-03-05T00:40:43.600 回答