The 'ofstream' function isn't opening the file?

My program is as follows:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ofstream jager;
jager.open("Hurr.txt");

cout<<"Now writing information into the file.\n";

jager << "Hello\n";
jager << "You\n";
jager << "I see what you are doing\n";


jager.close();
cout<<"Done.\n";
return 0;
}

It doesn't open the file, it doesn't write into it, I tried specifying the path more closely too but that didn't work either. What am I doing wrong?

Edit Ok so I was able to write into the file by specifying the correct path (had made a typo), but it still doesn't open or close any file. I don't see it open or close, is this how it's supposed to be or is there still something wrong?

Edit 2The file is already created, my question is whether the code is supposed to open the file so I can see it. Like when I run the code, is it supposed to open up the txt file for me to see, or does it do it all in the background? I was kinda expecting the file to pop up instead of it just showing me the cout strings

Ah thanks for clarifying that, much appreciated
Last edited on
It's not the code, because the code does exactly as expected on my machine. Are you sure it didn't create the file? Check again.
You will not see that the file is opened on the screen. You will only see what is written with std::cout. The file is opened so that the program can write to it and if everything works it should contain
1
2
3
Hello
You
I see what you are doing
after the program has ended.
Last edited on
Topic archived. No new replies allowed.