Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include "stdafx.h"
#include <string>
#include <iostream>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	ofstream myfile;
	myfile.open("C:\\example.txt", ofstream::out);
        //doesn't create the file and myfile.is_open() returns false
	myfile << "Writing this to a file.\n";
	myfile.close();
}


It's kinda frustrating when you have the need to ask questions of this kind.
Here it is, on a windows console application, ofstream is not creating any file at the given location, if I supply no-path, however, it does.
No matter if I use the constructor or the open function, still doesn't work
Posted

1 solution

Possibly your application has not the privileges for writing on the root folder of the main hard disk.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900