c++ - VC++ 与 G++,cout

标签 c++ visual-c++ compilation g++

我有一个关于 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;
}

我使用 VC++ (2012) 和 gcc 4.7.2 (MinGW) 得到相同的结果(“C:\windows”)。

关于c++ - VC++ 与 G++,cout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15213715/

相关文章:

c - 如何在C中实现AES加密?

c++ - 是否可以强制 MPI 在发送时始终阻塞?

compilation - 为什么Go编译版本比较庞大?

c++ - 错误 : "Application has failed to start because its side-by-side configuration is incorrect"

c++ - 从立方体数组中删除内部面的最佳方法是什么?

c++ - if/else 语句的输出不显示/变量赋值问题;初级程序员

c++ - ImageMagick 使用 qt ans magick++ 打开和写入图像

java - 在 .jj 文件中检测到左递归

c++ - 为什么c++中的qsort不是通过模板实现的

c++ - Variadic 模板函数参数和引用类型推导