VC++ vs. G++, cout

VC++ vs. G++, cout

本文关键字:cout G++ vs VC++      更新时间:2023-10-16

我有一个关于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" ^__^

修改代码后:

#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;
}

我得到相同的结果("C:windows")与vc++(2012)和gcc 4.7.2 (MinGW)。