jeudi 6 octobre 2022

Is there a method to making ofstream save the file it creates?

The following is my code.

#include <iostream>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

string name;

int main()
{
    vector<string> authors {};
    cout << "Add Author Name:\n";
    cin >> name;

    authors.push_back(name);
    ofstream file;
    file.open("data\\authors.txt");
    file << name;
    file.close();

    return 0;
}

When I go to the directory that the file is set, there is no file with the authors name. Is there a way to get the file to save? I’m trying to program a sort of cataloguing program for a personal library, just an easy beginner project.

Aucun commentaire:

Enregistrer un commentaire