简体   繁体   中英

Alternative to std::istream::ignore

std::istream::ignore discards characters until one compares equal to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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