c++ - 是否有用于解析小数的良好 C++ 工具?

标签 c++ algorithm c++11

<分区>

我的代码中有一个位置,其中有一个 std::string::const_iterator 类型的元素 iter 并且如果 *iter是小数的开头(即 -00.01.6012319.199< 形式的字符串的开头 等)然后我想推进 iter 直到它通过十进制字符串,我想存储十进制字符串。

对于场景的具体设置:

for (std::string::const_iterator iter(str.begin()), offend(str.end()); iter != offend; ++iter)
{
    if (iter == '(')
    {
       //... blah blah blah
    }
    else if (iter is the beginning of a decimal representation)
    {
       parse the decimal representation, store it in a string, advance iter to the character at the end of the decimal representation (or to offend -- whichever comes first)
    }
    else if (some other condition involving iter)
    {
       // ... blah blah blah
    } 
    //...
} 

是否有一个 C++ 工具可以用于这种情况?

最佳答案

如果我没理解你的问题,你可以使用 std::stod这会将捕获的字符串转换为 double 字符串。如果你只是想保留字符串格式的小数,然后从不同的字符串中提取它,你可以使用 string::substr用于提取。

关于c++ - 是否有用于解析小数的良好 C++ 工具?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28911889/

相关文章:

C++ memcpy() 棘手的使用,需要行为理解

c++ - 我怎样才能轻松地将枚举成员转换为 int?

c++ - C++ 中的位图图像操作

c++ - 在存储/内存中查找特定程序的基地址?

c++ - 如何伪造包含非虚函数的 C++ 类?

c++ - 算术序列 - 检查

algorithm - 以时、日、月、年显示相对时间

java - 在 Java Program Lab 中需要快速帮助

C++11 原子。为什么这个编译,而不是链接?

c++ - Qt 和 X11 全屏应用程序,同时阻止窗口管理器