检查指针的以下位置是否为空或行尾 C++

Check if the following position of a pointer is null or end of line C++

好吧,我在 C++ 中有一个字符串迭代器

std::string::iterator itB = itC->begin();

并且我想检查迭代器的下一个位置是否到达行尾。我试过这个:

if(*itB ++ != NULL)

还有这个:

itB++ == itC->end()

但现在我真的很困惑,我需要一些帮助,因为我是 C++ 指针方面的菜鸟。

您想检查它而不修改它。您的两次尝试都涉及修改 itB。如果你有 C++11,那只是 std::next:

std::next(itB) == itC->end()

如果你不这样做,就再做一个迭代器:

std::string::iterator next = itB;
++next;
next == itC->end()

虽然,在这种情况下,我们知道 std::string::iterator 是一个随机访问迭代器,所以我们也可以这样做:

itB + 1 == itC->end()

(前两个适用于任何迭代器类别)