VC++ vs. G++, cout
VC++ vs. G++, cout
我有一个关于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)。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- std::cout.imbue()多重调用
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- 在作为静态成员包含在另一个类中的类的构造函数中使用 cout
- 在 COUT 语句中使用 COUT 调用函数
- GCC 4.8.2 自动矢量化由于 cout 而失败
- std::cout输出int时出现编译错误
- 在这种情况下显式调用时,std::cout 如何更改析构函数的行为?
- C++ Setter/Getter,cout 工作,printf 失败
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 结构元素名称要 cout?
- 使用模板类重载 cout
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- 带有 cout 的指针在C++
- cout 指针时的实际数字
- COUT 无法提供输出可能是由于内联组装
- C++程序在一定行后未正确编译[cout语句]
- 如何在逗号后使用 cout 打印整数值,而无需在逗号后添加额外的零C++?