<分区>
我的代码中有一个位置,其中有一个 std::string::const_iterator
类型的元素 iter
并且如果 *iter
是小数的开头(即 -00.01
、.60
、12319.1
、99< 形式的字符串的开头
等)然后我想推进 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++
工具可以用于这种情况?