[英]How to move the file pointer to next character through “ifstream” without “getting” any character, just like “fseek” does?
seekg使用ios作為第二個參數,並且ios可以設置為end或beg或其他一些值,如下所示: http://www/cplusioplus.com
我只想讓指針移動到下一個字符,如何通過ifstream來完成?
編輯好吧,問題是我想要一個類似於fseek的ifstream中的 function ,它移動指針而不讀取任何內容。
ifstream fin(...);
// ...
fin.get(); // <--- move one character
// or
fin.ignore(); // <--- move one character
是的。 正如您似乎已經知道的那樣,它被稱為seekg()嗎?
std::ifstream is("plop.txt" );
// Do Stuff
is.seekg (1, std::ios::cur); // Move 1 character forward from the current position.
請注意,這與以下內容相同:
is.get();
// or
is.ignore();
閱讀seekg
的文檔並按照那里的說明使用ios_base::cur
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.