c++ - 使用 boost::lexical_cast<double>(string)

标签 c++ boost lexical-cast

我是初学者,需要解释为什么这不起作用:

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/

相关文章:

c++ - 共享内存中的 boost::lockfree::queue 出现问题(boost 1.53、gcc 4.7.2/clang 3.0-6ubuntu3)

c++ - 负数的 lexical_cast 在不同的机器上表现不同

c++ - 使用 c_str() 返回的指针删除动态分配的 std::string 是否会导致 C++ 中的内存泄漏?

c++ - 在空指针的情况下,shared_ptr 和 unique_ptr 的删除器的标准行为是否不同?

c++ - 如何使用字符串拆分数组?

c++ - 用于解释自定义 c++11 属性的 Clang/GCC 插件

c++ - Boost 1.64 和 Visual Studio 2017 的问题

c++ - 如何 spsc_queue.pop() 这个结构?

c++ - 用模板类重载 lexical_Cast