【发布时间】:2016-03-18 10:42:14
【问题描述】:
输出字符串后,例如20.58,我尝试使用boost::lexical_cast 将其转换为双精度。但是下一行代码没有运行,我的程序结束了,我得到了一个分段错误。
{
string temp = matches[1];
int size = temp.find_first_of("<"); //number of chars until "<"
temp.resize(size);
cout << "Match: " << temp << "\n";
Price[1] = boost::lexical_cast<double>(temp);
cout << "Price: $" << Price[1] << '\n';
//break;
}
输出:
Match: 20.96
RUN FINISHED; Segmentation fault; real time: 860ms; user: 0ms; system: 0ms
我更喜欢使用 std:stod;但我在 Mac OSX 10.6.8 上使用 netbeans,发现不支持 C++11。
【问题讨论】:
-
Price[1]是什么?你确定索引 1 在那里有效吗?
标签: c++ c++11 memory-management segmentation-fault c++98