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

289 views Asked by At

When I run this simple code in 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;
}

everything is OK, but in Windows (Windows 8 64 bits, mingw, g++ 4.8.1), I got "The program has stopped working" (the compilation works fine and -Wall produces no warning).

The same code compiled and executed in Visual Studio works correctly.

Any idea?

1

There are 1 answers

0
Greg82 On

The solution is to compile with -static-libgcc -static-libstdc++ (see here for an explaination). Thanks to @sftrabbit.