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