[英]VC++ vs. G++, cout
I have a question about VC++ if u compile this code in VC++ : 我有一个关于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;
}
i see only "C" and if i compile it by g++ i will see "C:\\Windows" what's the problem? 我只看到“ C”,如果我用g ++编译,我会看到“ C:\\ Windows”,这是什么问题? sure i should delete the first line "#include "stdafx"" under g++ :)
确保我应该删除g ++下的第一行“ #include“ stdafx”“ :)
and change "_tmain" to "main" ^__^ 并将“ _tmain”更改为“ main” ^ __ ^
After correcting the code: 更正代码后:
#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;
}
I get identical results ("C:\\windows") with both VC++ (2012) and gcc 4.7.2 (MinGW). 使用VC ++(2012)和gcc 4.7.2(MinGW),我得到相同的结果(“ C:\\ windows”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.