mercredi 27 janvier 2021

ofstream not outputting file

I'm trying to output some arrays to a file "output.txt". I run this code with no errors but no output file seems to be created to the working directory

ofstream myfile("output.txt");
    if (myfile.is_open()) {
        myfile << "t: " << endl;
        for (int i = 0; i < range; i++) {
            myfile << t[i] << " ";
        }
        cout << endl;
        myfile << "x_1: " << endl;
        for (int i = 0; i < range; i++) {
            myfile << x_1[i] << " ";
        }
        cout << endl;
        myfile << "y_1: " << endl;
        for (int i = 0; i < range; i++) {
            myfile << y_1[i] << " ";
        }
        cout << endl;
        myfile << "x_2: " << endl;
        for (int i = 0; i < range; i++) {
            myfile << x_2[i] << " ";
        }
        cout << endl;
        myfile << "y_2: " << endl;
        for (int i = 0; i < range; i++) {
            myfile << y_2[i] << " ";
        }
        cout << endl;
        myfile.close();

    }
    else cout << "Unable to open file";

What's the problem?

Aucun commentaire:

Enregistrer un commentaire