启用_GLIBCXX_DEBUG时,Stringstream无法使用双精度 [英] Stringstream not working with doubles when _GLIBCXX_DEBUG enabled

查看:142
本文介绍了启用_GLIBCXX_DEBUG时,Stringstream无法使用双精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用_GLIBCXX_DEBUG模式来帮助查找我的代码中的错误,但是我遇到了一个问题,我认为这是库中的错误,但是希望有人可以告诉我我只是在做错什么.这是一个再现问题的简短示例:

I'm using _GLIBCXX_DEBUG mode to help find errors in my code but I'm having a problem which I think is an error in the library, but hopefully someone can tell me I'm just doing something wrong. Here is a short example which repro's the problem:

#define _GLIBCXX_DEBUG
#include <iostream>
#include <sstream>

int main (int argc, const char * argv[]) {
    std::ostringstream ostr;
    ostr << 1.2;
    std::cout << "Result: " << ostr.str() << std::endl;
    return 0;
}

如果我注释掉#define,那么输出是(如预期的那样):

If I comment out the #define then the output is (as expected):

Result: 1.2

使用_GLIBCXX_DEBUG定义,但是输出很简单:

With the _GLIBCXX_DEBUG define in place however the output is simply:

Result:

我已将此问题跟踪到流的_M_num_put字段保留为NULL,这将导致在流中引发(并捕获)异常,并且导致该数字没有输出. _M_num_put应该是来自区域设置的std :: num_put(我不声称要了解它应该如何工作,这只是到目前为止我在搜索中所学到的.)

I've tracked this down to the _M_num_put field of the stream being left as NULL, which causes an exception to be thrown (and caught) in the stream and results in no output for the number. _M_num_put is supposed to be a std::num_put from the locale (I don't claim to understand how that's supposed to work, it's just what I've learned in my searching so far).

我正在使用XCode的Mac上运行此程序,并尝试使用"LLVM GCC 4.2"和"Apple LLVM Compiler 3.0"作为编译器,结果相同.

I'm running this on a Mac with XCode and have tried it with both "LLVM GCC 4.2" and "Apple LLVM Compiler 3.0" as the compiler with the same results.

在解决这个问题方面,我将不胜感激.我想继续在我的代码上以_GLIBCXX_DEBUG模式运行,但这会干扰到这一点.

I'd appreciate any help in solving this. I want to continue to run with _GLIBCXX_DEBUG mode on my code but this is interfering with that.

推荐答案

其他人已经看到了这个在cplusplus.com上此处也在stackoverflow .

Someone else has seen this over at cplusplus.com and here at stackoverflow, too.

共识是,这是Mac OS的gcc 4.2中的一个已知错误,由于该编译器不再更新,因此不太可能得到修复.

Consensus is that it is a known bug in gcc 4.2 for Mac OS, and since that compiler is no longer being updated, it is unlikely to ever be fixed.

在我看来,您可以(1)使用LLVM,或(2)构建自己的GCC并使用它.

Seems to me that you can either (1) use LLVM, or (2) build your own GCC and use it.

这篇关于启用_GLIBCXX_DEBUG时,Stringstream无法使用双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆