I am learning C++ and trying to write a program to create a text file on my desktop and write to it.
For some reason, the file is no where to be found on my desktop.
Here is my code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("C:\\Users\\MyName\\Desktop\\test.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
I am using Eclipse to build and compile my code. Is this the reason it's not writing a file to my desktop?
Worked for me too. I compiled and ran this on ubuntu. Try to run this from command line in Windows and check whether it works then or not.