Fstream C++doesn't work

I'm learning how to work with files in C++ I did absolutely everything as in the example. The console displays the message Good!, but the file is not created, and if you manually create a file, nothing is written there. What could be the problem?

#include "pch.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;


    int main()
    {
        string path = "piin.txt";
        ofstream fout;
        fout.open(path);

        if (!fout.is_open())
        {
            cout << " Bad!";
        }
        else
        {
            cout << " Good!";
            fout << "Мои данные";
        }
        fout.close();
    }
Author: Harry, 2018-12-08

2 answers

Most likely you are looking for the created file in the wrong directory :)
I don't remember exactly what the VS environment makes the current directory when running - so either look carefully in the subdirectories of the project, or specify the exact full name of the file - type "D:\\Programs\\Project\\pii.txt" (don't forget about the double backslashes).

 2
Author: Harry, 2018-12-08 07:02:05

I work in Visual Studio, the file was created and edited in the root folder of the project! In case of a similar situation, check there

 0
Author: Дядя Фея, 2018-12-08 07:10:55