Trần Ngọc Dũng
Trần Ngọc Dũng

Reputation: 11

cannot create a text file in C++

I'm using an ofstream object to create and print a string to a text file, but it doesn't work. this is my code :

#include <iostream>
#include <fstream>
using namesace std;
int main()
{
     ofstream output("d:\\data.txt");
     output << "this is my text" << endl;
     output.close();
     return 0;
}

The file data.txt was created when I set output("data.txt"). The text file was created in the same folder that contains the source code. But when I set output(d:\\data.txt) or any other location, it was not created at all. This code has also worked well in other computer and the problem only occurs in my laptop. I'm using visual stdio 2013 and operated by Windows 10 pro.

Upvotes: 1

Views: 465

Answers (1)

Jarvis
Jarvis

Reputation: 8564

Try making a file manually in d:\\, then get the complete, correct directory of the file from its properties. That way, you will know any mistakes you are making in specifying the directory of the file to be created.

Upvotes: 1

Related Questions