怎么用ios写入文件

1.有人知道用ios写入文件吗?

#include <iostream>
#include <fstream>

using namespace std;

char Username[40];
int main() {
    cout << "The copyright of this application belongs to Jerry studio. In case of copyright infringement, there will be a reward for reporting.";
    cout << "\n What's your name?";
    cin >> Username;
    cout << Username << ",Thank you for your help";
    ifstream  afile;
    afile.open("file.dat", ios::out | ios::in);
    return 0;
}

https://www.cplusplus.com/reference/fstream/basic_ofstream/basic_ofstream/