如何通过"ifstream"将文件指针移动到下一个字符而不"获取"任何字符,就像"fseek"一样?

Aqu*_*irl 4 c++ file-io ifstream

seekg使用ios作为第二个参数,ios可以设置为endbeg或其他一些值,如下所示:http://www.cplusplus.com/reference/iostream/ios/

我只想让指针移动到下一个字符,如何通过ifstream完成?

编辑 嗯,问题是我想在ifstream中使用类似于fseek的函数,它会移动指针而不读取任何内容.

ybu*_*ill 6

ifstream fin(...);
// ...

fin.get(); // <--- move one character
// or
fin.ignore(); // <--- move one character
Run Code Online (Sandbox Code Playgroud)

  • @Anisha:不,不会. (2认同)

Mar*_*ork 5

是。您似乎已经知道它的名为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)