我正在尝试使用std:getline(),但是遇到了奇怪的运行时错误:
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的特定错误。有什么提示吗?
更新: 该错误仅在调试模式下打印。如果我在发布模式下构建此代码,则一切正常。
更新2: 有关该问题的更多信息可以在此处找到。
解决方案:
在您的目标信息生成选项卡的预处理器宏中设置
_GLIBCXX_FULLY_DYNAMIC_STRING=1
系统信息:
OSX 10.6.2 | XCode 3.2 | g++ 4.2 | i386 的调试配置
g++
命令,然后考虑重新启动计算机,最后考虑重新安装开发工具。 - dmckee --- ex-moderator kitten