Aqu*_*irl 4 c++ file-io ifstream
seekg使用ios作为第二个参数,ios可以设置为end或beg或其他一些值,如下所示:http://www.cplusplus.com/reference/iostream/ios/
我只想让指针移动到下一个字符,如何通过ifstream完成?
编辑 嗯,问题是我想在ifstream中使用类似于fseek的函数,它会移动指针而不读取任何内容.
ifstream fin(...);
// ...
fin.get(); // <--- move one character
// or
fin.ignore(); // <--- move one character
Run Code Online (Sandbox Code Playgroud)
是。您似乎已经知道它的名为seekg()?
std::ifstream is("plop.txt" );
// Do Stuff
is.seekg (1, std::ios::cur); // Move 1 character forward from the current position.
Run Code Online (Sandbox Code Playgroud)
注意,这与以下内容相同:
is.get();
// or
is.ignore();
Run Code Online (Sandbox Code Playgroud)