当我在Ubuntu(Ubuntu 13.10,64 bits,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++
(see here for an explaination)进行编译。感谢@sftrabbit。
关于c++ - typeinfo name()和endl在Windows和mingw中不能一起使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20934566/