0
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
string a("hehe.txt");
ofstream aa;
aa.open(a.c_str());
aa<<"hehe"<<endl;
aa.close();
return 0;
}

I create a simple project in VS 2010 which contains only a main file as shown above. I was wondering where the "hehe.txt" is stored? I could not find it within the project.

tshepang
  • 12,111
  • 21
  • 91
  • 136
upceric
  • 131
  • 1
  • 4
  • At least on most OSes, it'll get opened in whatever is the "current directory" at the time (which could be nearly anywhere). – Jerry Coffin Mar 18 '13 at 15:29
  • http://stackoverflow.com/questions/143174 – Drew Dormann Mar 18 '13 at 15:32
  • As you have mentioned, it does exist in the "current directory". I didn't find it because I compile it without running it. I think I have to think twice before posting problems. Anyway, thank you for your response. – upceric Mar 18 '13 at 15:48

2 Answers2

1

The file will be created in the same folder as your .vcxproj and .cpp files.

Martin
  • 16,093
  • 1
  • 29
  • 48
0

It is typically stored in the directory where you started the executable. Check in the Debug or Release subdirectories under your project. You can change the working directory by specifying it in the Project Properties->Configuration Properties->Debugging.

unxnut
  • 8,509
  • 3
  • 27
  • 41