Okay, so Ive learned how to read a file and write into a file, but I want to know how to create a NEW file. How would I do this? Im using windows Vista and I want to create a new Notpad Document. Thanks for the help guys! :)
I could see where this would trip up a newer user it is a little odd.
1 2 3 4 5 6 7 8 9 10 11 12
#include<iostream>
#include<fstream> /*This is the important one*/
int main()
{
std::ofstream NewFile("TheDocument.txt", std::ios_base::out); /*I'm not using any namespaces */
/*Code Code Code*/
NewFile.close();
return 0;
}
You see when windows sees a file, it checks the extention of that file against a collection of known extentions kept in the registry. In this case ".txt" would be notepad so any file you create with a ".txt" extention will be opened with notepad.exe.
The interesting part is that it doesn't actually matter what is in that file, what it was meant to do or if the application that is registered to that extention is even capable of opening it. If you take your application and change it from "a.exe" to "a.doc" Windows will try to open it with what ever ".doc" is registered to.
EDIT: I forgot to mention that unless you specify the UNC path for the document it will be created in your current execution path when the application is run.
REEDIT: It just occured to me that you could mean you want to create a new FOLDER, is that the case?
No, you had it right. I want to create a new notepad.txt document. But where would I put the name, and where do I put where its located? (Documents, Picutres, Music)