I have some trouble with producing files in C++. I consulted this answer here but when I try using it, it doesn't produce a file. What I wrote:
//~/Documents/Test_CPP/ex2/main_2.cpp
#include <fstream>
int main()
{
std::ofstream file("Hello.txt");
// Hello.txt has been created here
}
I compile it with the command g++ main_2.cpp
and run it with ./a.out
. I don't really know what could go wrong here, except theorizing that the file might be produced not in the current directory but somewhere else. So I tried changing Hello.txt
to ~/Documents/Test_CPP/ex2/Hello.txt
, which doesn't change anything. What exactly am I doing wrong here?