Hey guys! I wanted some help on filenaming! I wanted the user to input the filename. Also if he could also input the file extension, it would be good. Mostly, I need the text file.
Please write your codes in C++. Any help would be appreciated. Thanks! :)
The open on line 21 takes char array as it's first argument.
Use C++11 compiler and use std::string without need to use unsafe c-strings ever again.
1 2 3 4 5
std::cout << "Enter name of file to open: ";
std::string filename;
std::getline(std::cin, filename);
ofstream diary;
diary.open(filename, ios::out);// or filename.c_str() if you have old compiler
Okay the .c_str() thing worked!! Thanks a lot! Now I am facing a new probelm! It just creates a file with that name! I want it to be a text file! What do I do? Thanks again!!
Thanks! That worked too! :D
I know this is going somewhere else but can you tell me how to use system's date and time so that I won't have to ask for it from the user?