gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 07:44:05 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com