簡體   English   中英

替代std :: istream :: ignore

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

std :: istream :: ignore丟棄字符,直到一個比較等於delim。 是否有其他處理字符串而不是字符的方法,即丟棄字符串直到一個比較等於指定字符的方法?

最簡單的方法是連續提取一個字符串,直到找到正確的字符串為止:

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

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

當然,這假定字符串用空格字符分隔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM