ofstream ignore
时间: 2023-08-29 20:12:40 浏览: 54
The `ignore` function in `ofstream` is used to ignore a specified number of characters from the output stream. It takes an integer parameter, which specifies the number of characters to ignore.
For example, consider the following code snippet:
```
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile("example.txt");
if (myfile.is_open()) {
myfile << "This is a line of text." << endl;
myfile.ignore(5); // ignore the first 5 characters in the output stream
myfile << "This is another line of text." << endl;
myfile.close();
}
return 0;
}
```
In this example, the `ignore` function is used to ignore the first 5 characters in the output stream before writing the second line of text. This will result in the output file containing the following two lines:
```
is a line of text.
This is another line of text.
```