C ++使用getline()prints:在XCode中没有分配释放的指针 [英] C++ using getline() prints: pointer being freed was not allocated in XCode

查看:235
本文介绍了C ++使用getline()prints:在XCode中没有分配释放的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用std:getline()但遇到一个奇怪的运行时错误:

I'm trying to use std:getline() but getting a strange runtime error:


malloc: *错误对象0x10000a720:未分配的指针未分配
*
在malloc_error_break中设置断点以调试

malloc: * error for object 0x10000a720: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

是产生此错误的代码:

//main.cpp
#include <iostream>
#include <sstream>

int main (int argc, char * const argv[])
{
   std::istringstream my_str("demo string with spaces");
   std::string word;

   while (std::getline(my_str, word, ' ')) {
        std::cout << word << std::endl;
   }
   return 0;
}

在每个单词之前,我得到这个错误。从评论中似乎是一个OSX / XCode特定的错误。有任何提示吗?

Before each word I get this error. From the comments it seems to be a OSX/XCode specific error. Any hints on that?

更新:
错误仅在调试模式下打印。

Update: The error is only printed in Debug mode. If I build this code in Release mode everything is fine.

更新2:
更多关于该问题的信息可以找到< a href =http://lists.apple.com/archives/cocoa-dev/2009/Sep/msg01199.html =nofollow>此处。

解决方案:

设置


_GLIBCXX_FULLY_DYNAMIC_STRING = 1

_GLIBCXX_FULLY_DYNAMIC_STRING=1

在您的预处理器宏中的目标信息构建标签中。

in your Preprocessor Macros in targets info build tab.

系统信息:


OSX 10.6.2 | XCode 3.2 | g ++ 4.2 |调试配置i386

OSX 10.6.2 | XCode 3.2 | g++ 4.2 | debug config for i386


推荐答案

至少有一个人报告了g ++ 4.2.1的问题苹果看起来可能与你的相关,不得不使用 _GLIBCXX_FULLY_DYNAMIC_STRING 定义不正确配置标准库(不是我理解我在这里键入的任何内容)。

At least one person has reported problems with g++ 4.2.1 on Apple that seem possibly related to yours having to do with an improper configuration of the standard library with the _GLIBCXX_FULLY_DYNAMIC_STRING definition (not that I understand any of what I'm typing here).

您可能会从新闻组线程中得到一些包含此消息的线索:

You might get a bit of a clue from the newsgroup thread that includes this message:

  • http://gcc.gnu.org/ml/gcc-bugs/2009-10/msg00807.html

这篇关于C ++使用getline()prints:在XCode中没有分配释放的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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