【问题标题】:typeinfo name() and endl don't work together in Windows and mingwtypeinfo name() 和 endl 在 Windows 和 mingw 中不能一起工作
【发布时间】:2014-01-22 22:44:54
【问题描述】:

当我在 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 中编译和执行的相同代码可以正常工作。

有什么想法吗?

【问题讨论】:

  • 您确定是因为对name 的调用导致它失败了吗?
  • @sftrabbit 是的,但我不明白为什么......
  • 奇怪的是,问题来自endl。如果我删除它,程序可以正常运行!?
  • 64 位 Windows? Have you had a look at this?
  • 这解决了问题!我必须用“-static-libgcc -static-libstdc++”编译。感谢您的宝贵时间!

标签: c++ windows-8 mingw typeid ubuntu-13.10


【解决方案1】:

解决办法是用-static-libgcc -static-libstdc++see here for an explaination)编译。感谢@sftrabbit。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-18
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2014-01-07
    • 2019-08-17
    • 2016-11-23
    • 2019-02-18
    相关资源
    最近更新 更多