I have a C++ project which I initially compiled with g++. Now, I am trying to make it work in Visual Studio 2010 and the problem is that the regular commands that create an empty output file for writing:
#include <fstream>
using namespace std;
ofstream fout("afile.txt");
fout<<"write someting"<<endl;
fout.close();
will not work in VS2010 (no file is created). Even if the file already exists nothing is written on it.
So, any ideas what is the correct way of opening a file for writing from C++ in VS2010 ?
My suspicion is that the file is created somewhere other than you expected – Check out where the working directory is pointing. This is 2012, but it is very similar if not the same… Right click on the project in vs2010, and select properties, Then select debugging and look at the working directory:
Alternitively, build it, and copy the app to a directory you create – Then run it on the command line to check whether its a permissions problem.