I am trying to create a program, where I prompt the user to name the output file name. I need the output file to be a .txt file. I know how to create, open and close an output file. But when I try to implement by asking user for the name, I am stuck. In addition, I am trying to let the user print out an entire sentence, but I can only get the first word. How would I fix this problem?
Another part of the program I am trying to solve is:
If the user chooses to open an existing file, it should show a list of all files that have been created with that program. The user types up the name of the file, and the program displays the contents of the file. Can anyone give me ideas of how I approach this problem.
int main (void)
//Part 1: create new file for user
ofstream outfile; // object for writing to a file
cout << "Enter the name of the file you wish to create: " << endl;
cin >> filename;
outfile.open (filename + ".txt"); //trying to make a .txt file
cout << "Enter a sentence: " << endl;
cin >> sentence;
outfile << sentence <<endl; // this line prints the first word not the entire sentence
outfile << "hello" << endl;
//Part 2: User can open existing file
Last edited by captjack; April 24th, 2012 at 01:19 AM.
I put it in a while loop, because I have more parts to program that I haven't started yet. I will be asking the user to open and close other files. So that's why it seems sort of pointless at this moment.