1
在输出字符串例如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。
什么是价格[1]'?你确定索引1在那里有效吗? –
请发表[mcve] – YSC