我正在尝试编写一个函数,该函数能够检测到什么时候我几乎处于串流结束处,但似乎不起作用。在串流结束时检测
下面是一些代码:
std::string path(1.2.3);
int number;
std::stringstream ss(path);
while (!ss.eof()) {
if (ss.peek() != '.') {
ss >> number;
if (ss.tellg() == path.length()) {
std::cout << "Last one: " << number;
} else {
std::cout << number;
}
} else { ss.get(); }
}
我尝试使用ss.tellg()== path.length(),但是,这并不工作。有人有另一种选择吗?
@戴夫这也不起作用。 – JNevens