2013-08-06 44 views
0

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

回答

1

最简单的方法是不断地提取字符串,直到你找到正确的:

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

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

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