| s1l3nt (5) | |
|
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? | |
|
|
|
| iHutch105 (1079) | |
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. | |
|
|
|
| s1l3nt (5) | |
| 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 | |
|
|
|
| iHutch105 (1079) | |
|
To create the file: http://www.cplusplus.com/reference/fstream/ofstream/ofstream/ To write to it: http://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/ | |
|
|
|