typeinfo name() 和 endl 在 Windows 和 mingw 中不能一起工作
typeinfo name() and endl don't work together in Windows and mingw
当我在Ubuntu(Ubuntu 13.10,64位,g++ 4.8.1)中运行这个简单的代码时:
#include <iostream>
#include <typeinfo>
#include <string>
using namespace std;
int main(void)
{
const type_info &ti_trait = typeid(char_traits<char>::char_type);
cout << "Traits character type name : " <<
ti_trait.name() << endl;
return 0;
}
一切都很好,但是在Windows(Windows 8 64位,mingw,g ++ 4.8.1)中,我得到了"程序已停止工作"(编译工作正常,-Wall没有发出警告)。
在Visual Studio中编译和执行的相同代码可以正常工作。
知道吗?
解决方案是使用 -static-libgcc -static-libstdc++
进行编译(有关解释,请参阅此处)。感谢@sftrabbit。
相关文章:
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的for循环不能正确获取argv
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 为什么我不能在 FOR LOOP 中使用 i/10,C++?
- 为什么我不能在不创建字符串变量的情况下使用函数的字符串输出
- 为什么模板类中的对象不能返回值
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 为什么我不能在 C++ 中的特定函数重载中调用同一函数的任何其他重载?
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 数组长度,为什么从命令行获取时不能使用它?
- C++程序使用 mingw 在 Linux 上交叉编译在 MSy2 中工作,但不能直接在 Windows 中工作
- typeinfo name() 和 endl 在 Windows 和 mingw 中不能一起工作
- 为什么我不能在 MinGW 中链接 64 位 .lib 文件?
- C++ 在 minGW-W64 g++ 中编译的代码不能使用 Ubuntu g++ 编译
- MinGW gcc C编译器有效,但g++不能
- 不能在 MinGW 中包含标头
- MinGW 4.8.1 不能使用 C++11
- 不能将getchar_unlocked与代码一起使用::块 + Windows 7 64 位上的 MingW
- 使用MinGW编译的DLL不能在使用Visual Studio编译器编译的c++代码中工作