how to create a file

I made a program to create a file but when I go to the given drive I dont find the file.

I made this.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>

#include<fstream>

using namespace std;

 

int main()

{

            

            ofstream outfile("D:\\output.txt");

 

// body of the program

 

                      outfile.close(); 

 

            return(0);

}


I went to d drive but I didn't find any .txt file.
You forgot
outfile.open();
If you tell the file name in the ofstream constructor, the file is open with no need of open method.

The fact that you don't find the file is quite strange, try to check if the file was open using outfile.is_open()
No , none of these programs is working.
I am not able to create a .txt file in D drive.
Can someone help me in this.




Last edited on
Try adding std::ios::out as a file flag.
where should I add this ?
Topic archived. No new replies allowed.