我是初学者,需要解释为什么这不起作用:
string myArray[620223];
//myArray is then populated with a while loop using ifstream and getline
string myString = myArray[9];
double myValue;
try {
myValue = boost::lexical_cast<double>(myString);
}
catch(boost::bad_lexical_cast const&) {
myValue = 0;
}
myArray[9] 不为零,但生成的 double 值始终为零。任何帮助将不胜感激。谢谢。
最佳答案
由于代码看起来不错,所以这是一个有根据的猜测。 myArray[9]
是第十个 数组元素。 myArray[0]
是第一个。您实际上想要第九个元素,myArray[8]
。
关于c++ - 使用 boost::lexical_cast<double>(string),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15693165/