Creating a file from console

Feb 8, 2013 at 5:47pm
So, I have question. I already know how to open a txt file so you can write data to it and close it but lets say I wanted to have a console application that prompts the user to enter in the name of a text file to create. So the user would enter in the name and then it would create a text file and allow you to edit the file.

So it would be like

Enter file name to create: example.txt

Opening example.txt

(allows you to edit example.txt (or whatever you called the file and then closes the file)

Is that possible and what would that look like?
Feb 8, 2013 at 5:49pm
Instead of a ifstream object that you'd use for reading the file, you'd use a ofstream object for writing a file.

http://www.cplusplus.com/reference/fstream/ofstream/

If the file doesn't exist, it'll create it. If the file does exist, it'll overwrite it.
Feb 8, 2013 at 7:27pm
So what would that look like in actual code? Sorry, I 'm very much a visual person and I need to see physical code or it wont make sense for me. An example would be fantastic
Feb 8, 2013 at 7:31pm
Topic archived. No new replies allowed.