Here is the code:
void makefiles(char* filename) {
    ifstream file(filename, ios::in);
    // number of entries in main file 
    int size = 0;
    // names is the vector that holds entries 
    vector<string> names;
    string tmpstr;
    while (getline(file, tmpstr)) {
        string toadd = "";
        for (int i = 0; i < tmpstr.size(); i++) {
            if (tmpstr[i] != '|')
                toadd += tmpstr[i];
            else
                break;
        }
        if(count(names.begin(), names.end(), toadd) == 0)
            names.push_back(toadd);
        size++;
    }
    file.close();
    ofstream userfile;
    file.open(filename, ios::in);
    for (int i = 0; i < names.size(); i++) {
        userfile.open(string(getenv("TEMP")) + "\\" + names[i] + ".txt", ios::out);
        
        cout << string(getenv("TEMP")) + "\\" + names[i] + ".txt" << endl;
        
        while (getline(file, tmpstr)) {
            if (tmpstr.rfind(names[i], 0) == 0) {
                userfile << tmpstr << endl;
                userfile.flush();
            }
        }
        userfile.close();
    }
    file.close();
}
This function is being called from main, filename contains some formatted text, like email database of the next view:
gottaletitout@gmail.com|timetogo@gmail.com|06.01.2023|21:09:30|born in the abyss|156
gottaletitout@gmail.com|timetogo@gmail.com|06.01.2023|21:09:30|born in the abyss|156
a@gmail.com|b@gmail.com|23.12.2009|13:52:16|prikol|13
hottaletitout@gmail.com|timetogo@gmail.com|06.01.2023|21:09:30|aorn in the abyss|156
Thus, one line is one entry
In conclusion, I get many empty files that have the names i want, but, again, they are empty
I tried adding right after opening userfile:
if(!userfile){
    cout << "File is not opened" << endl;
    return;
}
But it doesn't help because !userfile = false
I tried instead of userfile << tmpstr << endl, using userfile << tmpstr << flush;
 
     
    