简体   繁体   English

替代std :: istream :: ignore

[英]Alternative to std::istream::ignore

std::istream::ignore discards characters until one compares equal to delim. std :: istream :: ignore丢弃字符,直到一个比较等于delim。 Is there an alternative working on strings rather then chars, ie one that discards strings until one compares equal to the specified? 是否有其他处理字符串而不是字符的方法,即丢弃字符串直到一个比较等于指定字符的方法?

The easiest way would be to continuously extract a string until you find the right one: 最简单的方法是连续提取一个字符串,直到找到正确的字符串为止:

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

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

This assumes that the strings are delimited with whitespace characters, of course. 当然,这假定字符串用空格字符分隔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM