I wrote to a file called "test.txt" and I tried to look for it and could not find it anywhere using search engines. I thought the file does not exist, but I wrote another code that reads from the same file "test.txt", it reads it successfully. Any idea where the file should be located at?
Writing code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile ("test.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
In the same location as your binary..
if you use a tool like visual studio is creates it in another location and adds debug data... so the file would be over there...
if you run the binary directly it would be created in the same folder.
#include <iostream>
#include <fstream>
usingnamespace std;
int main () {
ofstream myfile ("test.txt");
if (myfile.is_open())
{
myfile << "This is a line.\n";
myfile << "This is another line.\n";
myfile.close();
system ("dir test.txt");
// system ("type test.txt");
system("pause");
}
else
{
cout << "Unable to open file";
system ("dir test.txt");
}
return 0;
}