替代std :: istream :: ignore

时间:2013-08-06 07:20:59

标签: c++ fstream

std :: istream :: ignore丢弃字符,直到一个比较等于delim。有没有一个替代工作字符串而不是字符,即丢弃字符串直到一个比较等于指定的字符串?

1 个答案:

答案 0 :(得分:1)

最简单的方法是连续提取字符串,直到找到合适的字符串:

std::istringstream iss;
std::string str;
std::string pattern = "find me";

while ( iss >> str && str != pattern ) ;
if (!iss) { /* Error occured */ }

这假定字符串用空格字符分隔。当然。

相关问题