I know how to make a text file and let the user input it's name and save it to the application directory. How would I let the user input the name for the text file and then save it to a directory besides the application directory.?
For example I let the user input the text file name. I would want my program to save it to c:/somefolder
That works however, when I am wanting the user to input some text into it, it doesn't save the text. It will create the text file but there wont be anything on there. I've been trying to figure this out for hours!
1. It doesn't matter if there are spaces in the filename the user inputs, you just have to use std::getline because std::cin only extracts input until the next whitespace character.
2. You should delete line 12, line 10 already opens the file correctly - you're only causing problems.
3. Are you checking the file with the program still open? Usually the file is closed automatically at the end of the program and sometimes stuff isn't written to the file until it gets closed.
Unless something you did caused an error (like line 12), then there isn't really much wrong with the code to write to the file.
Also, use the std::getline function that works with std::string, not character arrays - what if the user enters more than 3000 characters? I think you also meant to getline once and not twice.