typeinfo name() 和 endl 在 Windows 和 mingw 中不能一起工作

typeinfo name() and endl don't work together in Windows and mingw

本文关键字:mingw 不能 工作 一起 Windows name endl typeinfo      更新时间:2023-10-16

当我在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。