Im a novice in the C++ programming language and ive been using the book C++ Without Fear to help myself get a grip on the language. One of the activities in the book is writing a Word processor "like" program.
What I'd like to do is write it so that the user doesn't have to enter a preexisting file name to begin. I'd like to have the program create a file with the name the user inputs and save it to a Folder that exists already.
Also I'm sure this is much more complicated to do but later on I'd like to be able to add a feature where it will print what you input when your done. Any tips on how to accomplish this would be appreciated...sorry i didnt think about defining print but yes i meant onto physical paper. As it turns out your right it will create the file i just didnt know it. o.o
Code:#include <iostream> #include <fstream> using namespace std; int main() { char filename[81]; char input_line[81]; // Input line for text entry cout << "Enter a file name and press ENTER: "; cin.getline(filename, 80); ofstream file_out(filename); if (! file_out) { cout << "File " << filename << " could not be opened."; //if file opening fails return -1; } cout << "File " << filename << " was opened." << endl; while (1) { cout << "Enter line (~~~ to quit)>>"; cin.getline(input_line, 80); if (strcmp(input_line, "~~~") == 0) break; file_out << input_line << endl; } file_out.close(); return 0; }



LinkBack URL
About LinkBacks


