【发布时间】:2013-12-13 17:13:45
【问题描述】:
我正在尝试编写一个函数,该函数将检测我何时接近字符串流的末尾,但它似乎不起作用。
这里有一些代码:
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(),但这不起作用。有人有替代品吗?
【问题讨论】:
-
@Dave 那也不行。
标签: c++ string stringstream