those aren't the actual codes, obviously, just asking how I can make the user make their own file name: cin >> filename
and then make a file out of the name they made.
Please help!
Edit:
filename += ".txt"
myfile.open (filename);
this mix didn't work :'(
Edit:
Surprisingly, this cut down on those HUGE errors, but still doesn't work :'(
Maybe make a string variable like string filename; and get the user to input the filename into that. Then, do something like Filename.append(".txt"). That should get you a filename and extension. Then maybe use the filename variable to create your file? I haven't tried this out as I am on my iPad, but in theory, it might work. :)
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
usingnamespace std;
int main () {
string line;
string name;
string age;
string time;
string folder;
cout<<"Please enter new text file name. Certain \
symbols are not accepted, check your computer's \
handbook for details(if you have already made a \
folder, press Enter)";
cout<<endl;
getline (cin, folder);
cout<<endl;
folder += ".txt";
if (!folder.empty())
{
cout << "Enter your name";
cout << endl;
getline (cin, name);
cout << endl;
cout << "Enter your age";
cout << endl;
getline (cin, age);
cout << endl;
cout << "Enter the time";
cout << endl;
getline (cin, time);
cout << endl;
ofstream myfile;
myfile.open (("\"") (folder) ("\""));
myfile << name;
myfile << endl;
myfile << age;
myfile << endl;
myfile << time;
myfile << endl;
myfile.close();
}
elseif (folder.empty())
cout<<endl;
ifstream myfile (("\"")folder("\""));
if (myfile.is_open() && myfile.good())
{
cout<<"Here are your entries\n\n";
getline (myfile, line);
cout << "name:";
cout << line;
cout << endl;
getline (myfile, line);
cout << "age:";
cout << line;
cout << endl;
getline (myfile, line);
cout << "time submitted:";
cout << line;
cout << endl;
myfile.close();
}
else
cout << "Unable to open file";
getch ();
return 0;
}
it just won't recognize folder when it compiles, so I don't know if it's impossible for the person using the program to make a name of their own, or what, but it definitely should be possible.
oh, I see... Alright, so if I go like string filename = "c:\\windows\\users\\desktop" or something of equal stature, it would place the direct file to the desktop. That's interesting, I'll test it in the morning.
Alright, well I still haven't figured this problem out yet, does anybody know how to make it possible for the user to enter in a variable and then to make a text document out of the word(s) they wrote? For example: